local extension = Package:new("hxqunyou")
extension.extensionName = "b-huixiang"

Fk:loadTranslationTable{
  ["hxqunyou"] = "回想群友包",
}

local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["hxqunyou__chgs"] = "催花高手",
  ["designer:hxqunyou__chgs"] = "催花高手",
  ["hx__niyongwoyong"] = "用用",
  [":hx__niyongwoyong"] = "【你用？我用！】每回合每种牌名限一次，一名角色使用牌时，你可以将此牌的目标改为一名你选择的角色。",
  ["#hx__niyongwoyong-choose"] = "你用？我用！：你可以将此牌的目标改为一名你选择的角色",
  ["hx__ziyong"] = "自用",
  [":hx__ziyong"] = "出牌阶段限一次，你可以弃置一张牌然后摸x张牌（x为你弃置的牌的点数）。",
  ["hx__tayong"] = "她用",
  [":hx__tayong"] = "锁定技，你的回合内，防止你受到的伤害、体力流失以及体力上限减少。",
  ["$hx__niyongwoyong1"] = "Sunney哥哥~  叫我Sunney！",
  ["$hx__niyongwoyong2"] = "Sunney哥~哥~",
  ["$hx__ziyong"] = "大声发！！！",
  ["$hx__tayong1"] = "你有病啊？",
  ["$hx__tayong2"] = "卧~艹~啊！",
  ["~hxqunyou__chgs"] = "（啊哈哈哈）龙哥龙哥龙哥！",
}

local hxqunyou__chgs = General:new(extension, "hxqunyou__chgs","god",4)

local hx__niyongwoyong = fk.CreateTriggerSkill {
  name = "hx__niyongwoyong",
  anim_type = "offensive",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if not self or not data.card then
      return false
  end
    return player:hasSkill(self) and data.card
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cardName = data.card.trueName
    local used = player:getTableMark("hx_nywy_used") or {}
    if used[cardName] then return false end
    local originalTarget = TargetGroup.getRealTargets(data.tos)[1]
    local candidates = table.filter(room:getAlivePlayers(), function(p) 
      return p.id ~= originalTarget 
    end)
    if #candidates == 0 then return false end
    local prompt = "#hx__niyongwoyong-choose:::"..data.card:toLogString()
    local target_p = room:askForChoosePlayers(player, table.map(candidates, Util.IdMapper), 1, 1, prompt, self.name, true)
    if #target_p > 0 then
      self.cost_data = {
        newTarget = target_p[1],
        cardName = cardName
      }
      return true
    end
    return false
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local costData = self.cost_data
    data.tos = { { costData.newTarget } }
    local used = player:getTableMark("hx_nywy_used") or {}
    used[costData.cardName] = true
    room:setPlayerMark(player, "hx_nywy_used", used)
  end
}
local clear = fk.CreateTriggerSkill{
  name = "#hx_nywy_clear",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, p, data)
    return target == p and data.from == Player.NotActive
  end,
  on_use = function(self, event, target, p, data)
    p.room:setPlayerMark(p, "hx_nywy_used", {})
  end
}

hxqunyou__chgs:addSkill(hx__niyongwoyong)
hx__niyongwoyong:addRelatedSkill(clear)

local hx__ziyong = fk.CreateActiveSkill{
  name = "hx__ziyong",
  anim_type = "drawcard",
  card_num = 1,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and
      not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, player, player)
    if player.dead then return end
    local card = Fk:getCardById(effect.cards[1])
    local x = card.number
    player:drawCards(x, "hx__ziyong")
  end,
}

hxqunyou__chgs:addSkill(hx__ziyong)

local hx__tayong = fk.CreateTriggerSkill{
  name = "hx__tayong",
  frequency = Skill.Compulsory,
  anim_type = "defensive",
  events = { fk.DamageInflicted, fk.PreHpLost, fk.BeforeMaxHpChanged},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player.phase ~= Player.NotActive then
      return player == target and (event == fk.DamageInflicted or event == fk.PreHpLost or (event == fk.BeforeMaxHpChanged and data.num < 0 ))
    end
  end,
  on_use = function(self, event, target, player, data)
    return true
  end,
}

hxqunyou__chgs:addSkill(hx__tayong)
--[[
Fk:loadTranslationTable{

  ["hxqunyou__pindian"] = "拼点高手",
  ["designer:hxqunyou__pindian"] = "非电竞恐龙/庆思书",
  ["hx__pindian"] = "拼点",
  [":hx__pindian"] = "出牌阶段，你可以与一名其他角色拼点，若你赢或点数相同，你获得双方拼点牌并摸一张牌,且你可以重复此流程；反之，此技能本回合失效。",
  ["#hx__pindian-confirm"] = "拼点：你可以选择一名其他角色与其再次拼点",
}

local hxqunyou__pindian = General:new(extension, "hxqunyou__pindian","god",4)

local hx__pindian = fk.CreateActiveSkill{
  name = "hx__pindian",
  anim_type = "drawcard",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    if player:isKongcheng() then return false end
    return true
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    if #selected > 0 or to_select == Self.id then return false end
    return Self:canPindian(Fk:currentRoom():getPlayerById(to_select))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local pindian = player:pindian({target}, self.name)
    if pindian.results[target.id].winner == player or pindian.fromCard.number == pindian.results[target.id].toCard.number then
      player.room:drawCards(player, 1, self.name)
      local ids = {}
      for _, card in ipairs({pindian.fromCard, pindian.results[target.id].toCard}) do
        if room:getCardArea(card) == Card.DiscardPile then
          table.insertIfNeed(ids, card:getEffectiveId())
        end
      end
      if #ids > 0 and not player.dead then
        room:moveCards({
          ids = ids,
          to = player.id,
          toArea = Player.Hand,
          moveReason = fk.ReasonPrey,
          proposer = player.id,
          skillName = self.name,
        })
      end
      if not player.dead then
        room:askForUseActiveSkill(player, "hx__pindian", "#hx__pindian-confirm", true,{}, false)
      end
    else
      room:invalidateSkill(player, self.name, "-turn")
    end
  end,
}



hxqunyou__pindian:addSkill(hx__pindian)
--]]
local hxqunyou__jimiheng = General:new(extension, "hxqunyou__jimiheng","god",4)
Fk:loadTranslationTable{
  ["hxqunyou__jimiheng"] = "急祢衡",
  ["#hxqunyou__jimiheng"] = "你先别急",
  ["designer:hxqunyou__jimiheng"] = "水精灵",
  ["hx__bieji"] = "别急",
  [":hx__bieji"] = "锁定技，当一名其他角色在一个回合内累计发动5次技能时，其死亡。",
  ["@hx__bieji-turn"] = "急",
  ["$hx__bieji"] = "尔等竖子，不堪为伍！",
  ["~hxqunyou__jimiheng"] = "呵呵呵呵……这天地都容不下我！……",
}

local hx__bieji = fk.CreateTriggerSkill{
  name = "hx__bieji",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.AfterSkillEffect},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target and target ~= player and player.room.logic:getCurrentEvent().can_hx__bieji
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:killPlayer({who =target.id})
  end,
  refresh_events = {fk.AfterSkillEffect},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target and target ~= player and
    target:hasSkill(data) and data.visible and not player.room.logic:getCurrentEvent().hx__bieji_counted
  end,
  on_refresh = function(self, event, target, player, data)
      local room = target.room
      local cur = room.logic:getCurrentEvent()
      cur.hx__bieji_counted = true
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player, self.name, "offensive", {target.id})
      room:doIndicate(player.id, {target.id})
      room:addPlayerMark(target, "@hx__bieji-turn", 1)
      if (target:getMark("@hx__bieji-turn") >= 5) then
          cur.can_hx__bieji = true
      end
  end,
}
hxqunyou__jimiheng:addSkill(hx__bieji)

local hxqunyou__qiamimiao = General:new(extension, "hxqunyou__qiamimiao","god",2,3)
Fk:loadTranslationTable{

  ["hxqunyou__qiamimiao"] = "恰米喵",
  ["designer:hxqunyou__qiamimiao"] = "焉",
  ["hx__qiami"] = "恰米",
  [":hx__qiami"] = "当一名角色使用一张牌指定目标后，你可弃置你的一种花色的所有牌，令此牌额外结算x次。（x为你以此法弃置的牌数）",
  ["hx__zhaocai"] = "昭财",
  [":hx__zhaocai"] = "你的手牌数小于已损失体力时，你可以与一名角色各摸一张牌。该角色以此法摸的牌因使用或打出而失去后，其减少一点体力上限。",
  ["#hx__qiami-choose"] = "恰米：请选择要弃置的一种花色",
  ["#hx__zhaocai-choose"] = "昭财：请选择摸牌的角色",
  ["@hx__zhaocai"] = "招",
  ["$hx__qiami"] = "看我的一百大洋~",
  ["$hx__zhaocai"] = "你想要的话，那就分给你吧~",
}

local hx__qiami = fk.CreateTriggerSkill{
  name = "hx__qiami",
  anim_type = "drawcard",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return not target.dead and player:hasSkill(self) and data.card and not player:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local suits = {}
    local suitid = {}
    for _, cid in ipairs(player.player_cards[Player.Hand]) do
      local card = Fk:getCardById(cid)
      local suitname = card:getSuitString(true)
      if not (suitname == "nosuit" or table.contains(suits, suitname)) then
        table.insert(suits, suitname)
        table.insert(suitid, Fk:getCardById(cid).suit)
      end
    end
    if #suits ~= 0 then
      local choice = room:askForChoice(player, table.connect({"Cancel"}, suits), self.name, "#hx__qiami-choose", false)
      if choice ~= "Cancel" then
        self.cost_data = suitid[table.indexOf(suits, choice)]
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local suit = self.cost_data
    local discard = table.filter(player.player_cards[Player.Hand], function(cid)
      return Fk:getCardById(cid).suit == suit
    end)
    room:throwCard(discard, self.name, player, player)
    local x = #discard
    if x > 0 then
      data.additionalEffect = (data.additionalEffect or 0) + x
    end
  end,
}
local hx__zhaocai = fk.CreateTriggerSkill{
  name = "hx__zhaocai",
  anim_type = "drawcard",
  events = {fk.HpChanged, fk.MaxHpChanged, fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:getHandcardNum() < player:getLostHp() then
      if event == fk.AfterCardsMove then
        for _, move in ipairs(data) do
          if move.from == player.id then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand then
                return true
              end
            end
          end
        end
      else
        return target == player
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local targets = table.map(player.room.alive_players, Util.IdMapper)
    local to = player.room:askForChoosePlayers(player, targets, 1, 1, "#hx__zhaocai-choose", self.name, true)
    if #to > 0 then
      self.cost_data = {tos = to}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    player.room:drawCards(player, 1, self.name)
    local card = player.room:drawCards(to, 1, self.name)
    room:setCardMark(Fk:getCardById(card[1]), "@hx__zhaocai", "")
    room:setCardMark(Fk:getCardById(card[1]), "hx__zhaocai_info", {player.id, to.id, 0})
  end,
}

local hx__zhaocai_trigger = fk.CreateTriggerSkill{
  name = "#hx__zhaocai_trigger",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.from == player.id and (move.moveReason == fk.ReasonUse or move.moveReason == fk.ReasonResonpse) then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand and Fk:getCardById(info.cardId):getMark("hx__zhaocai_info") ~= 0 then
            return true
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, move in ipairs(data) do
      if move.from == player.id and (move.moveReason == fk.ReasonUse or move.moveReason == fk.ReasonResonpse) then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand and Fk:getCardById(info.cardId):getMark("hx__zhaocai_info") ~= 0 then
            local card = Fk:getCardById(info.cardId)
            local mark = card:getMark("hx__zhaocai_info")
            room:setCardMark(card, "@hx__zhaocai", 0)
            local src = room:getPlayerById(mark[1])
            if not src.dead and src:hasSkill(hx__zhaocai) then
              if not player.dead then
                room:changeMaxHp(player,-1)
              end
            end
            room:setCardMark(card, "hx__zhaocai_info", 0)
          end
        end
      end
    end
  end,
}

hxqunyou__qiamimiao:addSkill(hx__qiami)
hxqunyou__qiamimiao:addSkill(hx__zhaocai)
hx__zhaocai:addRelatedSkill(hx__zhaocai_trigger)


local hxqunyou__guinv = General:new(extension, "hxqunyou__guinv","god",2,4,General.Female)
Fk:loadTranslationTable{
  ["hxqunyou__guinv"] = "鬼女",
  ["designer:hxqunyou__guinv"] = "烟",
  ["hx__haren"] = "哈人",
  [":hx__haren"] = "锁定技，你造成或受到的伤害改为X（X为你的体力值）。",
  ["hx__chouxiang"] = "抽象",
  [":hx__chouxiang"] = "你死亡时，你可以令一名其他角色获得【哈人】。",
  ["#hx__chouxiang-choose"] = "抽象：请选择获得【哈人】的角色",
}

local hx__haren = fk.CreateTriggerSkill{
  name = "hx__haren",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused, fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
      if not player:hasSkill(self.name) then return false end
      if event == fk.DamageCaused then
          return target == player and data.to
      else
          return target == player
      end
  end,
  on_use = function(self, event, target, player, data)
      local room = player.room
      local x = player.hp
      if event == fk.DamageCaused then
        data.damage = x
      else
        data.damage = x
      end
  end,
}

local hx__chouxiang = fk.CreateTriggerSkill{
  name = "hx__chouxiang",
  anim_type = "negative",
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self, false, true)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room:getAlivePlayers(), function(p)
      return not p:hasSkill(self) end), Util.IdMapper)
    if #targets == 0 then return end
    local to = room:askForChoosePlayers(player, targets, 1, 1, "#hx__chouxiang-choose", self.name, false)
    if #to > 0 then
      to = to[1]
    else
      to = table.random(targets)
    end
    room:handleAddLoseSkills(room:getPlayerById(to), "hx__haren", nil, true, false)
  end,

  refresh_events = {fk.EnterDying},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_refresh = function(self, event, target, player, data)
    player:broadcastSkillInvoke(self.name)
    player.room:notifySkillInvoked(player, self.name)
  end,
}

hxqunyou__guinv:addSkill(hx__haren)
hxqunyou__guinv:addSkill(hx__chouxiang)

--[[
local hxqunyou__liujinliupei = General:new(extension, "hxqunyou__liujinliupei","wei",3)
Fk:loadTranslationTable{
  ["hxqunyou__liujinliupei"] = "刘衿刘佩",
  ["#hxqunyou__liujinliupei"] = "并蒂连枝",
  ["designer:hxqunyou__liujinliupei"] = "手枪顿豆腐",
  ["hx__qixin"] = "契心",
  [":hx__qixin"] = "当你不以此法发动以下效果时，你可以发动另一项：①使用一张基本牌 ②摸两张牌。",
  ["hx__jiusi"] = "纠思",
  [":hx__jiusi"] = "每回合限一次，你可以将一名角色的一张牌当做一张基本牌使用或打出，若其因此失去一个区域内的全部牌，你翻面。",
  ["$hx__qixin1"] = "姐妹称心，有灵犀栖心田。",
  ["$hx__qixin2"] = "暮雪纷纷落，心同往，不患无乡。",
  ["$hx__jiusi1"] = "双姝出宫墙，飞雪白了少年头。",
  ["$hx__jiusi2"] = "心鹿徙南北，我何处西东？",
  ["~hxqunyou__liujinliupei"] = "阿姊，我冷。不冷了，不冷了。",
  ["#hx__qixin_choice"] = "契心：你可以使用一张基本牌",
  ["#hx__jiusi_choose"] = "纠思：请选择一名角色并选择其的一张牌",
  ["@@hx__qixin"] = "契心",
} 
--——————————————①可以触发②但②不能触发①
local hx__qixin = fk.CreateTriggerSkill{
  name = "hx__qixin",
  anim_type = "positive",
  events = {fk.AfterCardsMove,fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove and player:hasSkill(self) then
      local x = 0
      for _, move in ipairs(data) do
        if move.toArea == Card.PlayerHand and move.to and move.moveReason == fk.DrawNCards then
          x = x + #move.moveInfo
          if x == 2 then
            return true
          end
        end
      end
    elseif data.card and data.card.type == Card.TypeBasic and player:hasSkill(self) then
    return target == player
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      local all_names = U.getAllCardNames("b")
      local names = table.filter(all_names, function (name)
        local card = Fk:cloneCard(name)
        return player:canUse(card, {bypass_times = false}) and not player:prohibitUse(card)
      end)
      local use = room:askForUseCard(player, self.name, table.concat(names, ","), "#hx__qixin_choice", true, {bypass_times = false})
      if use then
        use.extraUse = false
        room:useCard(use)
      end
    elseif data.card and data.card.type == Card.TypeBasic then
      player:drawCards(2, self.name, nil, "@@hx__qixin")
    end
  end,
}
--没测，纯半成品
local os__mouli = fk.CreateViewAsSkill{
  name = "os__mouli",
  card_filter = Util.FalseFunc,
  card_num = 0,
  pattern = ".|.|.|.|.|basic",
  interaction = function(self)
    local allCardNames, cardNames = {}, {}
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id)
      local name = card.name
      if not table.contains(allCardNames, name) and card.type == Card.TypeBasic and not card.is_derived then
        table.insert(allCardNames, name)
        local card = Fk:cloneCard(name)
        if not Self:prohibitUse(card) and ((Fk.currentResponsePattern == nil and Self:canUse(card)) or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card))) then
          table.insert(cardNames, name)
        end
      end
    end
    return UI.ComboBox { choices = cardNames , all_choices = allCardNames }
  end,
  view_as = function(self)
    local choice = self.interaction.data
    if not choice then return end
    local c = Fk:cloneCard(choice)
    c.skillName = self.name
    return c
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name) == 0
  end,
  enabled_at_response = function(self, player, cardResponsing)
    return player:usedSkillTimes(self.name) == 0 and not cardResponsing
  end,
  before_use = function(self, player, use)
    local targets = table.filter(player.room:getAlivePlayers(), function(p) return not p:isNude() end)
    if #targets < 1 then return "" end
    local card = player.room:askForCardChosen(player, targets, "he", self.name, "#hx__jiusi_choose")
    local cids = player.room:getCardsFromPileByRule(".|.|.|.|" .. use.card.name)
    if #cids > 0 then
      use.card:addSubcards(cids)
    else
      player.room:doBroadcastNotify("ShowToast", Fk:translate("os__mouliFailed"))
      return self.name
    end
  end,
}
hxqunyou__liujinliupei:addSkill(hx__qixin)
--]]

local hxqunyou__songxingnu = General:new(extension, "hxqunyou__songxingnu","qun",4,4,General.Female)
Fk:loadTranslationTable{
  ["hxqunyou__songxingnu"] = "怂·星奴",
  ["#hxqunyou__songxingnu"] = "包变脸的",
  ["designer:hxqunyou__songxingnu"] = "星奴",
  ["hx__bianlian"] = "变脸",
  [":hx__bianlian"] = "转换技，当你手牌变化或体力变化时，阳：你摸一张牌并回复一点体力。阴：你令一名角色弃置一张牌并流失一点体力。（以此法造成的影响不会触发此技能）",
  ["#hx__bianlian-choose"] = "变脸：请选择一名角色令其弃置一张牌并流失一点体力！",
  ["#hx__bianlian-discard"] = "变脸：请选择一张牌弃置",
  ["hx__jinwu"] = "金武",
  [":hx__jinwu"] = "锁定技，当你使用武器牌后，你造成的所有伤害加一（最高加四）。",
  ["@hx__jinwu_mark"] = "金武",
  ["hx__shuangzhen"] = "双阵",
  ["#hx__shuangzhen_other"] = "双阵",
  [":hx__shuangzhen"] = "双阵：每两回合限两次（发动后之后的两回合内没有再次发动则清除场上所有“阵”），你可以于出牌阶段/你使用牌时/有角色进入濒死状态时/你成为牌的目标时/执行一项：1.若场上没有“阵”，你令你和一名角色获得“阵”然后回复一点体力并增加一点护甲；2.若场上有“阵”，你令有“阵”的角色各摸两张牌并回复一点体力然后移去所有“阵”。",
  ["$hx__bianlian1"] = "别打了，别打了，我错了。。。",
  ["$hx__bianlian2"] = "吃剑气吧，废物！",
  ["$hx__jinwu1"] = "嘿嘿，我开到金武了~",
  ["$hx__jinwu2"] = "燕燕于飞，寒江照孤影。",
  ["@hx__shuangzhen_mark"] = "阵",
  ["#hx__shuangzhen-choose"] = "请选择一名角色令其与你一起获得“阵”然后回复一点体力并增加一点护甲。",
  ["hx__shuangzhen_prompt1"] = "双阵1：你可以选择一名角色获得与其一起获得“阵”然后回复一点体力并增加一点护甲。",
  ["hx__shuangzhen_prompt2"] = "双阵2：你可以令有“阵”的角色各摸两张牌并回复一点体力然后移去所有“阵”。（若要发动，请直接选自己）",
}
local hx__bianlian = fk.CreateTriggerSkill{
  name = "hx__bianlian",
  mute = true,
  switch_skill_name = "hx__bianlian",
  events = {fk.AfterCardsMove, fk.HpChanged},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self.name) or player.dead then
      return false
    end
    if event == fk.HpChanged then
      if event == fk.HpLost and data.reason ~= self.name then
        return target == player
      end
    elseif event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Player.Hand and move.skillName ~= self.name then
          return true
        end
        for _, info in ipairs(move.moveInfo) do
          if move.from == player.id and info.fromArea == Player.Hand and move.skillName ~= self.name then
            return true
          end
        end
      end
    end
    return false
  end,
  on_cost = function(self, event, target, player, data)
    if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
      self.cost_data = player
      return true
    end
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skillState = player:getSwitchSkillState(self.name, true)
    if skillState == fk.SwitchYang then
      player:broadcastSkillInvoke(self.name,1)
      player:drawCards(1, self.name)
      room:recover{
        who = player,
        num = 1,
        reason = self.name,
      }
    else
      player:broadcastSkillInvoke(self.name,2)
      local alivePlayers = room:getAlivePlayers()
      local targets = table.filter(alivePlayers, function(p) return not p.dead end)
      local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#hx__bianlian-choose", self.name, false)
      local chosenPlayer = room:getPlayerById(to[1])
      room:askForDiscard(chosenPlayer, 1, 1, true, self.name, false, ".", "#hx__bianlian-discard")
      room:loseHp(chosenPlayer, 1, self.name)
    end
  end,
}

local hx__jinwu = fk.CreateTriggerSkill{
  name = "hx__jinwu",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished,fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    if event == fk.DamageCaused and data.from == player and player:hasSkill(self) and player:getMark("@hx__jinwu_mark") ~= 0 then
      return true
    elseif player:hasSkill(self) and event == fk.CardUseFinished and target == player and player:getMark("@hx__jinwu_mark") < 4 then
      return data.card and data.card.type == Card.TypeEquip and Fk:getCardById(data.card.id).sub_type == Card.SubtypeWeapon
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUseFinished and data.card and data.card.type == Card.TypeEquip and player:getMark("@hx__jinwu_mark") < 4 then
      room:addPlayerMark(player, "@hx__jinwu_mark", 1)
    elseif event == fk.DamageCaused and data.from == player and player:hasSkill(self) and player:getMark("@hx__jinwu_mark") ~= 0 then
      data.damage = data.damage + player:getMark("@hx__jinwu_mark")
    end
  end,
}

local hx__shuangzhen = fk.CreateActiveSkill{
  name = "hx__shuangzhen",
  anim_type = "support",
  can_use = function(self, player)
    return player.phase == Player.Play
  end,
  card_filter = function(self, to_select, selected)
    return false
  end,
  card_num = 0,
  target_filter = function(self, to_select, selected)
    if Self:getMark("hx__shuangzhen_count") < 2 then
      if Self:getMark("@hx__shuangzhen_mark") == 0 then
        return #selected == 0
      else
        return #selected == 0 and to_select == Self.id and Self:getMark("hx__shuangzhen2") > 0
      end
    end
  end,
  target_num = 1,
  prompt = function(self, selected, selected_cards)
		if Self:getMark("@hx__shuangzhen_mark") == 0 then
			return "hx__shuangzhen_prompt1"
		else
			return "hx__shuangzhen_prompt2"
		end
    end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:addPlayerMark(player, "hx__shuangzhen_can", 1)
    room:addPlayerMark(player, "hx__shuangzhen_count", 1)
    if player:getMark("@hx__shuangzhen_mark") == 0 then
      room:addPlayerMark(target, "@hx__shuangzhen_mark", 1)
      room:addPlayerMark(player, "@hx__shuangzhen_mark", 1)
      room:recover{who = player, num = 1, reason = self.name}
      room:recover{who = target, num = 1, reason = self.name}
      room:changeShield(player,1)
      room:changeShield(target,1)
      room:addPlayerMark(player, "hx__shuangzhen2", 1)
    else
      if player:getMark("hx__shuangzhen2") > 0 then
        for _, p in ipairs(room:getAlivePlayers()) do
          if p:getMark("@hx__shuangzhen_mark") > 0 then
            room:drawCards(p,2,self.name)
            room:recover{who = p, num = 1, reason = self.name}
            room:setPlayerMark(p, "@hx__shuangzhen_mark", 0)
          end
        end
        room:setPlayerMark(player, "hx__shuangzhen2", 0)
      end
    end
  end,
}

local hx__shuangzhen_other = fk.CreateTriggerSkill{
  name = "#hx__shuangzhen_other",
  anim_type = "support",
  events = {fk.CardUseFinished,fk.EnterDying,fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:getMark("hx__shuangzhen_count") < 2 then
      if player:getMark("hx__shuangzhen2") == 0 then
        if player:getMark("@hx__shuangzhen_mark") == 0 then
          if event == fk.CardUseFinished and target == player then
            return true
          elseif event == fk.EnterDying then
            return true
          elseif event == fk.TargetConfirmed and target == player then
            return true
          end
        end
      else
        if event == fk.CardUseFinished and target == player then
          return true
        elseif event == fk.EnterDying then
          return true
        elseif event == fk.TargetConfirmed and target == player then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "hx__shuangzhen_can", 1)
    room:addPlayerMark(player, "hx__shuangzhen_count", 1)
    if player:getMark("hx__shuangzhen2") > 0 then
      for _, p in ipairs(room:getAlivePlayers()) do
        if p:getMark("@hx__shuangzhen_mark") > 0 then
          room:drawCards(p,2,self.name)
          room:recover{who = p, num = 1, reason = self.name}
          room:setPlayerMark(p, "@hx__shuangzhen_mark", 0)
        end
      end
      room:setPlayerMark(player, "hx__shuangzhen2", 0)
    else
      local target = room:askForChoosePlayers(player, table.map(room:getAlivePlayers(), Util.IdMapper), 1, 1, "#hx__shuangzhen-choose", self.name, false)
      local to = room:getPlayerById(target[1])
      room:addPlayerMark(to, "@hx__shuangzhen_mark", 1)
      room:addPlayerMark(player, "@hx__shuangzhen_mark", 1)
      room:recover{who = player, num = 1, reason = self.name}
      room:recover{who = to, num = 1, reason = self.name}
      room:changeShield(player,1)
      room:changeShield(to,1)
      room:addPlayerMark(player, "hx__shuangzhen2", 1)
    end
  end,
}
local hx__shuangzhen_remove = fk.CreateTriggerSkill{
  name = "#hx__shuangzhen_remove",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if  player:hasSkill(self) then
      if event == fk.TurnEnd and player:getMark("hx__shuangzhen_can") > 0 then
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "hx__shuangzhen1", 1)
    if player:getMark("hx__shuangzhen_can") == 1 then
      if player:getMark("hx__shuangzhen2") == 1 then
        room:setPlayerMark(player, "hx__shuangzhen_can", 2)
        room:setPlayerMark(player, "hx__shuangzhen2", 2)
        room:setPlayerMark(player, "hx__shuangzhen1", 0)
      end
    end
    if player:getMark("hx__shuangzhen_can") >= 2 and player:getMark("hx__shuangzhen1") == 2 then
      room:setPlayerMark(player, "hx__shuangzhen2", 0)
      for _, p in ipairs(room:getAlivePlayers()) do
        if p:getMark("@hx__shuangzhen_mark") > 0 then
          room:setPlayerMark(p, "@hx__shuangzhen_mark", 0)
        end
      end
      room:setPlayerMark(player, "hx__shuangzhen_can", 0)
      room:setPlayerMark(player, "hx__shuangzhen_count", 0)
      room:setPlayerMark(player, "hx__shuangzhen1", 0)
    end
  end,
}

hxqunyou__songxingnu:addSkill(hx__bianlian)
hxqunyou__songxingnu:addSkill(hx__jinwu)
hxqunyou__songxingnu:addSkill(hx__shuangzhen)
hx__shuangzhen:addRelatedSkill(hx__shuangzhen_other)
hx__shuangzhen:addRelatedSkill(hx__shuangzhen_remove)


local hxqunyou__wuming = General:new(extension, "hxqunyou__wuming","qun",4)
Fk:loadTranslationTable{
  ["hxqunyou__wuming"] = "无名",
  ["designer:hxqunyou__wuming"] = "手枪顿豆腐",
  ["hx__cengxiangshi"] = "曾相识",
  [":hx__cengxiangshi"] = "当你不以此法使用一张①类型的牌时，你可弃置一张非①类型的②类型的牌，视为使用一张非①②类型且不为延时类锦囊的③类型的牌（不计入次数），若③类型为装备牌，则改为你可以重铸一张牌。",
  ["hx__yanguilai"] = "燕归来",
  [":hx__yanguilai"] = "当你连续使用一种类型的牌后，若手中无以此法获得的牌，你可以摸两张牌。",
  ["@@hx__yanguilai-inhand"] = "燕归来",
  ["#hx__cengxiangshi-ask"] = "请弃置一张非此牌类型的牌。",
  ["#hx__cengxiangshi-recast"] = "你可以重铸一张牌。",
  ["#hx__cengxiangshi-target"] = "请选择此牌目标",
} 
local hx__cengxiangshi = fk.CreateTriggerSkill{
  name = "hx__cengxiangshi",
  anim_type = "offensive",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.card and not table.contains(data.card.skillNames, self.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.card.type == Card.TypeBasic then
      local card1 = table.filter(player:getCardIds("he"), function(id) return Fk:getCardById(id).type == Card.TypeEquip or Fk:getCardById(id).type == Card.TypeTrick end)
      if #card1 == 0 then return end
      local discard1 = room:askForDiscard(player,1,1,true,self.name,false,".|.|.|.|.|trick,equip","#hx__cengxiangshi-ask")
      if #discard1 == 0 then return end
      if Fk:getCardById(discard1[1]).type == Card.TypeEquip then
        U.askForUseVirtualCard(room, player, U.getAllCardNames("t"), nil, self.name,"#hx__cengxiangshi-target", false)
      elseif Fk:getCardById(discard1[1]).type == Card.TypeTrick then
        local cid1 = room:askForCardsChosen(player,player,0,1,"he",self.name,"#hx__cengxiangshi-recast")
        if #cid1 > 0 then
          room:recastCard(cid1,player,self.name)
        end
      end
    elseif data.card.type == Card.TypeTrick then
      local card2 = table.filter(player:getCardIds("he"), function(id) return Fk:getCardById(id).type == Card.TypeEquip or Fk:getCardById(id).type == Card.TypeBasic end)
      if #card2 == 0 then return end
      local discard2 = room:askForDiscard(player,1,1,true,self.name,false,".|.|.|.|.|basic,equip","#hx__cengxiangshi-ask")
      if #discard2 == 0 then return end
      if Fk:getCardById(discard2[1]).type == Card.TypeEquip then
        U.askForUseVirtualCard(room, player, U.getAllCardNames("b"), nil,self.name, "#hx__cengxiangshi-target", false)
      elseif Fk:getCardById(discard2[1]).type == Card.TypeBasic then
        local cid2 = room:askForCardsChosen(player,player,0,1,"he",self.name,"#hx__cengxiangshi-recast")
        if #cid2 > 0 then
          room:recastCard(cid2,player,self.name)
        end
      end
    elseif data.card.type == Card.TypeEquip then
      local card3 = table.filter(player:getCardIds("he"), function(id) return Fk:getCardById(id).type == Card.TypeTrick or Fk:getCardById(id).type == Card.TypeBasic end)
      if #card3 == 0 then return end
      local discard3 = room:askForDiscard(player,1,1,false,self.name,false,".|.|.|.|.|trick,basic","#hx__cengxiangshi-ask")
      if #discard3 == 0 then return end
      if Fk:getCardById(discard3[1]).type == Card.TypeTrick then
        U.askForUseVirtualCard(room, player, U.getAllCardNames("b"), nil,self.name, "#hx__cengxiangshi-target", false)
      elseif Fk:getCardById(discard3[1]).type == Card.TypeBasic then
        U.askForUseVirtualCard(room, player, U.getAllCardNames("t"), nil,self.name, "#hx__cengxiangshi-target", false)
      end
    end
  end,
}

local hx__yanguilai = fk.CreateTriggerSkill{
  name = "hx__yanguilai",
  anim_type = "drawcard",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    local card = table.filter(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@hx__yanguilai-inhand") > 0 end)
    if #card > 0 then return end
    local currentEvent = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
    if not currentEvent then return end
    local n1 = 1
    local n2 = 1
    local n3 = 1
    local events = player.room.logic.event_recorder[GameEvent.UseCard] or Util.DummyTable
    for i = #events, 1, -1 do
      local e = events[i]
      if e.id < currentEvent.id then
        local use = e.data[1]
        if use.from == player.id then
          if use.card.type == Card.TypeBasic then
            n1 = n1 + 1
          else
            break
          end
        end
      end
    end
    for i2 = #events, 1, -1 do
      local e2 = events[i2]
      if e2.id < currentEvent.id then
        local use2 = e2.data[1]
        if use2.from == player.id then
          if use2.card.type == Card.TypeTrick then
            n2 = n2 + 1
          else
            break
          end
        end
      end
    end
    for i3 = #events, 1, -1 do
      local e3 = events[i3]
      if e3.id < currentEvent.id then
        local use3 = e3.data[1]
        if use3.from == player.id then
          if use3.card.type == Card.TypeEquip then
            n3 = n3 + 1
          else
            break
          end
        end
      end
    end
    if n1 > 1  then
      return player:hasSkill(self) and target == player and data.card.type == Card.TypeBasic
    elseif n2 > 1 then
      return player:hasSkill(self) and target == player and data.card.type == Card.TypeTrick
    elseif n3 > 1 then
      return player:hasSkill(self) and target == player and data.card.type == Card.TypeEquip
    else
      return false
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(2,self.name,nil,"@@hx__yanguilai-inhand")
  end,
}
hxqunyou__wuming:addSkill(hx__cengxiangshi)
hxqunyou__wuming:addSkill(hx__yanguilai)

local hxqunyou__ytys = General:new(extension, "hxqunyou__ytys","qun",4)
Fk:loadTranslationTable{
  ["hxqunyou__ytys"] = "袁谭&袁尚",
  ["#hxqunyou__ytys"] = " 兄弟倪墙",
  ["designer:hxqunyou__ytys"] = "大闲者八雲紫",
  ["hx__neifa"] = "内伐",
  [":hx__neifa"] = "出牌阶段开始时，你可以摸两张牌，然后选择至多两种类型并弃置手牌中所选类型的牌，直到本阶段结束，你不能使用这些类型的牌且若你选择了两项则你使用非装备牌可以多选或少选一个目标。当你使用一张本回合未选择过的类型的牌时，摸X张牌（X为本回合以此法弃置的牌数且至多为5）。",
  ["#hx__neifa-choice"] = "请选择至多两种类型",
  ["@hx__neifa__basic"] = "基本",
  ["@hx__neifa__trick"] = "锦囊",
  ["@hx__neifa__equip"] = "装备",
  ["@hx__neifa__draw"] = "内伐摸牌",
  ["#hx__neifa_trigger-choose"] = "内伐：你可以为%arg增加/减少1个目标",
  ["#hx__neifa_trigger"] = "内伐",
  ["#hx__neifa_mod"] = "内伐",
  ["$hx__neifa1"] = "承嗣之统，向来立长，而不立幼。（君王之稷，自古尊贤，而不尊愚。）",
  ["$hx__neifa2"] = "长兄如父，今日定要好好管教于你！（兵无盔，将无甲，不知兄长，以何管教？）",
  ["~hxqunyou__ytys"] = "我没有你这样的兄弟，哼！",
}

local hx__neifa = fk.CreateTriggerSkill{
  name = "hx__neifa",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart,fk.CardUsing,fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self) and player.phase == Player.Play
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      player:drawCards(2, self.name)
      local choices = room:askForChoices(player, {"@hx__neifa__basic", "@hx__neifa__trick", "@hx__neifa__equip"}, 1, 2, self.name, "#hx__neifa-choice", true)
      if #choices == 0 then return false end
      for _, choice in ipairs(choices) do
        if choice == "@hx__neifa__basic" then
          room:addPlayerMark(player, "@hx__neifa__basic", 1)
        elseif choice == "@hx__neifa__trick" then
          room:addPlayerMark(player, "@hx__neifa__trick", 1)
        elseif choice == "@hx__neifa__equip" then
          room:addPlayerMark(player, "@hx__neifa__equip", 1)
        end
      end
      local discardCount = 0
      for _, cardId in ipairs(player:getCardIds("h")) do
        local card = Fk:getCardById(cardId)
        if table.contains(choices, "@hx__neifa__basic") and card.type == Card.TypeBasic then
          room:throwCard({cardId}, self.name, player, player)
          discardCount = discardCount + 1
        elseif table.contains(choices, "@hx__neifa__trick") and card.type == Card.TypeTrick then
          room:throwCard({cardId}, self.name, player, player)
          discardCount = discardCount + 1
        elseif table.contains(choices, "@hx__neifa__equip") and card.type == Card.TypeEquip then
          room:throwCard({cardId}, self.name, player, player)
          discardCount = discardCount + 1
        end
      end
      if discardCount > 0 and discardCount < 5 then
        room:setPlayerMark(player, "@hx__neifa__draw", discardCount)
      elseif discardCount >= 5 then
        room:setPlayerMark(player, "@hx__neifa__draw", 5)
      end
    end
  end,
}

local hx__neifa_mod = fk.CreateTriggerSkill{
  name = "#hx__neifa_mod",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing,fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardUsing then
      return target == player and player:hasSkill(self) and player:getMark("@hx__neifa__draw") > 0
    elseif event == fk.EventPhaseEnd then
      return target == player and player:hasSkill(self) and player.phase == Player.Play
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing and player:getMark("@hx__neifa__draw") > 0 then
      local card = data.card
      local basic_mark = player:getMark("@hx__neifa__basic")
      local trick_mark = player:getMark("@hx__neifa__trick")
      local equip_mark = player:getMark("@hx__neifa__equip")
      local drawCount = player:getMark("@hx__neifa__draw")
      if basic_mark > 0 then
        if trick_mark > 0 and card.type == Card.TypeEquip then
          player:drawCards(drawCount, self.name)
        end
        if equip_mark > 0 and card.type == Card.TypeTrick then
          player:drawCards(drawCount, self.name)
        end
        if trick_mark == 0 and equip_mark == 0 and card.type ~= Card.TypeBasic then
          player:drawCards(drawCount, self.name)
        end
      elseif trick_mark > 0 then
        if equip_mark > 0 and card.type == Card.TypeBasic then
          player:drawCards(drawCount, self.name)
        end
        if basic_mark == 0 and equip_mark == 0 and card.type ~= Card.TypeTrick then
          player:drawCards(drawCount, self.name)
        end
      elseif equip_mark > 0 then
        if basic_mark == 0 and trick_mark == 0 and card.type ~= Card.TypeEquip then
          player:drawCards(drawCount, self.name)
        end
      end
    end
    if event == fk.EventPhaseEnd then
      if player:getMark("@hx__neifa__draw") > 0 or player:getMark("@hx__neifa__basic") > 0 or player:getMark("@hx__neifa__trick") > 0 or player:getMark("@hx__neifa__equip") > 0 then
        room:setPlayerMark(player, "@hx__neifa__draw", 0)
        room:setPlayerMark(player, "@hx__neifa__basic", 0)
        room:setPlayerMark(player, "@hx__neifa__trick", 0)
        room:setPlayerMark(player, "@hx__neifa__equip", 0)
      end
    end
  end,
}

local hx__neifa_prohibit = fk.CreateProhibitSkill {
  name = "#hx__neifa_prohibit",
  prohibit_use = function(self, player, card)
    if player:getMark("@hx__neifa__basic") ~= 0 and card.type == Card.TypeBasic then return true end
    if player:getMark("@hx__neifa__trick") ~= 0 and card.type == Card.TypeTrick then return true end
    if player:getMark("@hx__neifa__equip") ~= 0 and card.type == Card.TypeEquip then return true end
  end,
}

local hx__neifa_trigger = fk.CreateTriggerSkill{
  name = "#hx__neifa_trigger",
  mute = true,
  events = {fk.AfterCardTargetDeclared},
  can_trigger = function(self, event, target, player, data)
    if player:getMark("@hx__neifa__basic") > 0 and player:getMark("@hx__neifa__trick") > 0
    or player:getMark("@hx__neifa__basic") > 0 and player:getMark("@hx__neifa__equip") > 0 
    or player:getMark("@hx__neifa__trick") > 0 and player:getMark("@hx__neifa__equip") > 0 then
      return data.tos and #player.room:getUseExtraTargets( data, false) > 0 and target == player
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = player.room:getUseExtraTargets(data)
    local to = room:askForChoosePlayers(player, targets, 1, 1, "#hx__neifa_trigger-choose:::"..data.card:toLogString(),
    hx__neifa.name, true, false, "addandcanceltarget_tip", TargetGroup:getRealTargets(data.tos))
    if #to > 0 then
      self.cost_data = to
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(hx__neifa.name)
    local room = player.room
    if table.contains(TargetGroup:getRealTargets(data.tos), self.cost_data[1]) then
      TargetGroup:removeTarget(data.tos, self.cost_data[1])
      room:sendLog{ type = "#RemoveTargetsBySkill", from = target.id, to = self.cost_data, arg = hx__neifa.name, arg2 = data.card:toLogString() }
    else
      table.insert(data.tos, self.cost_data)
      room:sendLog{ type = "#AddTargetsBySkill", from = target.id, to = self.cost_data, arg = hx__neifa.name, arg2 = data.card:toLogString() }
    end
  end,
}


hxqunyou__ytys:addSkill(hx__neifa)
hx__neifa:addRelatedSkill(hx__neifa_mod)
hx__neifa:addRelatedSkill(hx__neifa_prohibit)
hx__neifa:addRelatedSkill(hx__neifa_trigger)

local hxqunyou__dabai = General:new(extension, "hxqunyou__dabai","qun",4)
Fk:loadTranslationTable{
  ["hxqunyou__dabai"] = "大白",
  ["designer:hxqunyou__dabai"] = "焉",
  ["hx__minga"] = "鸣啊",
  [":hx__minga"] = "你不因此技能失去牌或摸牌时，你可以摸一张牌并用一张手牌与任意名其他角色同时拼点。",
  ["hx__haqi"] = "哈气",
  [":hx__haqi"] = "锁定技,当一名角色一次性摸两张以上的牌时，你改为令所有角色各摸一张牌。",
  ["#hx__minga-choose"] = "请选择任意名其他角色与他们同时拼点",
}

local hx__minga = fk.CreateTriggerSkill{
  name = "hx__minga",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Player.Hand and move.skillName ~= self.name then
          return true
        end
      end
      for _, move in ipairs(data) do
        if move.from == player.id and move.skillName ~= self.name then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, self.name)
    local pd_targets = table.filter(room:getOtherPlayers(player), function (p) return player:canPindian(p) end)
    if not player:isKongcheng() and #pd_targets > 0 then
      local tos = room:askForChoosePlayers(player, table.map(pd_targets, Util.IdMapper), 1, #pd_targets, "#hx__minga-choose", self.name, true)
      if #tos > 0 then
        tos = table.map(tos, Util.Id2PlayerMapper)
        local pindian = player:pindian(tos, self.name)
      end
    end
  end,
}

local hx__haqi = fk.CreateTriggerSkill{
  name = "hx__haqi",
  anim_type = "drawcard",
  events = {fk.BeforeDrawCard},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.num > 1
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    data.num = data.num - 999
    for _, p in ipairs(room.alive_players) do
      p:drawCards(1, self.name)
    end
  end,
}


hxqunyou__dabai:addSkill(hx__minga)
hxqunyou__dabai:addSkill(hx__haqi)

local hxqunyou__genie = General:new(extension, "hxqunyou__genie","qun",4)
Fk:loadTranslationTable{
  ["hxqunyou__genie"] = "盖聂",
  ["#hxqunyou__genie"] = "剑圣",
  ["designer:hxqunyou__genie"] = "手枪顿豆腐",
  ["hx__yuanheng"] = "渊衡",
  [":hx__yuanheng"] = "锁定技，满足以下条件之一时你视为使用一张【杀】或【树上开花】：①不因此技能使用锦囊牌时且使用的上一张牌也是锦囊牌；②使用装备牌时。若本回①与②的满足次数之差=2，你获得一张牌堆或弃牌堆中因满足条件时使用的对应牌，然后此技能本回合失效。",
  ["hx__zongheng"] = "纵衡",
  ["#hx__zongheng_sha"] = "纵横",
  [":hx__zongheng"] = "当你造成伤害后，你可以选择X次：1.重置“渊衡”或“纵横”；2.使用下一张【杀】后发动“变装”；3.摸一张牌。（每项能选也最多每回合触发序号次，X为发动此技能时的剩余项数）",
  ["#hx__yuanheng-choose"] = "请选择一名其他角色",
  ["@hx__yuanheng_equip"] = "渊衡②",
  ["@hx__yuanheng_trick"] = "渊衡①",
  ["@@hx__yuanheng-phase"] = "渊衡",
  ["hx__yuanheng_slash"] = "视为使用一张【杀】",
  ["hx__yuanheng_tree"] = "视为使用一张【树上开花】",
  ["hx__zongheng_reset"] = "重置“渊衡”或“纵横”",
  ["hx__zongheng_reset_yuanheng"] = "重置“渊衡”",
  ["hx__zongheng_reset_zongheng"] = "重置“纵横”",
  ["hx__zongheng_slash"] = "使用下一张【杀】后发动“变装”",
  ["hx__zongheng_draw"] = "摸一张牌",
  ["@hx__zongheng_reset"] = "纵横1.",
  ["@hx__zongheng_slash"] = "纵横2.",
  ["@hx__zongheng_draw"] = "纵横3.",
  ["@@hx__zongheng_slash"] = "杀增益",
  ["$hx__yuanheng1"] = "了解你的对手，才能选择获胜的方式，失败的人只有一种，就是在抵达成功之前，放弃的人。",
  ["$hx__yuanheng2"] = "你完全依赖手中的剑，缺忘记了一件最基本的事情，持剑的人才是力量的真正源泉。",
  ["$hx__zongheng1"] = "横剑攻于技，以求其利，视为捭。",
  ["$hx__zongheng2"] = "纵剑攻于势，以求其实，视为阖。",
}

local hx__yuanheng = fk.CreateTriggerSkill{
  name = "hx__yuanheng",
  anim_type = "special",
  events = {fk.CardUsing},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player and data.card.type == Card.TypeEquip then
      return true
    end
    local currentEvent = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
    if not currentEvent then return end
    local n = 1
    local events = player.room.logic.event_recorder[GameEvent.UseCard] or Util.DummyTable
    for i = #events, 1, -1 do
      local e = events[i]
      if e.id < currentEvent.id then
        local use = e.data[1]
        if use.from == player.id then
          if use.card.type == Card.TypeTrick then
            n = n + 1
          else
            break
          end
        end
      end
    end
    if n > 1 then
      return player:hasSkill(self) and target == player and data.card.type == Card.TypeTrick and data.card.skillName ~= self.name
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {"hx__yuanheng_slash", "hx__yuanheng_tree"}
    if data.card.type == Card.TypeEquip then
      room:addPlayerMark(player, "@hx__yuanheng_equip", 1)
      room:addCardMark(data.card, "@@hx__yuanheng-phase")
      local choose = room:askForChoice(player, choices, self.name)
      if choose == "hx__yuanheng_slash" then
        local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#hx__yuanheng-choose", self.name, true)
        if #to == 0 then return end
        if #to > 0 then
            room:useVirtualCard("slash", nil, player, room:getPlayerById(to[1]), self.name, true)
        end
      elseif choose == "hx__yuanheng_tree" then
        if not player:isNude() then
          room:useVirtualCard("bogus_flower", nil, player, player, self.name, true)
        end
      end
    elseif data.card.type == Card.TypeTrick then
      room:addPlayerMark(player, "@hx__yuanheng_trick", 1)
      room:addCardMark(data.card, "@@hx__yuanheng-phase")
      local choose = room:askForChoice(player, choices, self.name)
      if choose == "hx__yuanheng_slash" then
        local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#hx__yuanheng-choose", self.name, true)
        if #to == 0 then return end
        if #to > 0 then
            room:useVirtualCard("slash", nil, player, room:getPlayerById(to[1]), self.name, true)
            
        end
      elseif choose == "hx__yuanheng_tree" then
        if not player:isNude() then
          room:useVirtualCard("bogus_flower", nil, player, player, self.name, true)
        end
      end
    end
    if (player:getMark("@hx__yuanheng_equip") - player:getMark("@hx__yuanheng_trick") == 2) or (player:getMark("@hx__yuanheng_trick") - player:getMark("@hx__yuanheng_equip") == 2) then
      local cards = table.filter(room.draw_pile, function (id)
        return Fk:getCardById(id):getMark("@@hx__yuanheng-phase") ~= 0
      end)
      table.insertTable(cards, table.filter(room.discard_pile, function (id)
        return Fk:getCardById(id):getMark("@@hx__yuanheng-phase") ~= 0
      end))
      for _, p in ipairs(room:getAllPlayers()) do
        table.insertTable(cards, table.filter(p:getCardIds("he"), function (id)
          return Fk:getCardById(id):getMark("@@hx__yuanheng-phase") ~= 0
        end))
      end
      if #cards > 0 then
        room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
      end
      room:setPlayerMark(player, "@hx__yuanheng_equip", 0)
      room:setPlayerMark(player, "@hx__yuanheng_trick", 0)
      room:invalidateSkill(player, self.name, "-turn")
    end
  end,
}

local hx__zongheng = fk.CreateTriggerSkill{
  name = "hx__zongheng",
  anim_type = "offensive",
  events = {fk.Damage,fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.TurnEnd then
      return player:hasSkill(self) and target == player and (player:getMark("@hx__zongheng_reset") > 0 or player:getMark("@hx__zongheng_slash") > 0 or player:getMark("@hx__zongheng_draw") > 0)
    else
      return target == player and player:hasSkill(self.name) and (player:getMark("@hx__zongheng_reset") == 0 or player:getMark("@hx__zongheng_slash") < 1 or player:getMark("@hx__zongheng_draw") < 2)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnEnd then
      room:setPlayerMark(player, "@hx__zongheng_reset", 0)
      room:setPlayerMark(player, "@hx__zongheng_slash", 0)
      room:setPlayerMark(player, "@hx__zongheng_draw", 0)
    else
      local choices = { }
      if player:getMark("@hx__zongheng_reset") == 0 then
        table.insert(choices, "hx__zongheng_reset")
      end
      if player:getMark("@hx__zongheng_slash") < 2 then
        table.insert(choices, "hx__zongheng_slash")
      end
      if player:getMark("@hx__zongheng_draw") < 3 then
        table.insert(choices, "hx__zongheng_draw")
      end
      for i = 1, #choices do
        local choose = room:askForChoice(player, choices, self.name)     
        if choose == "hx__zongheng_reset" and player:getMark("@hx__zongheng_reset") == 0 then
          local reset = room:askForChoice(player, {"hx__zongheng_reset_yuanheng", "hx__zongheng_reset_zongheng"}, self.name)
          if reset == "hx__zongheng_reset_yuanheng" then
            room:addPlayerMark(player, "@hx__zongheng_reset", 1)
            room:validateSkill(player, "hx__yuanheng", "-turn")
          elseif reset == "hx__zongheng_reset_zongheng" then
            room:addPlayerMark(player, "@hx__zongheng_reset", 1)
            room:setPlayerMark(player, "@hx__zongheng_reset", 0)
            room:setPlayerMark(player, "@hx__zongheng_slash", 0)
            room:setPlayerMark(player, "@hx__zongheng_draw", 0)
          end
        elseif choose == "hx__zongheng_slash" and player:getMark("@hx__zongheng_slash") < 2 then
          room:addPlayerMark(player, "@hx__zongheng_slash", 1)
          room:addPlayerMark(player, "@@hx__zongheng_slash")
        elseif choose == "hx__zongheng_draw" and player:getMark("@hx__zongheng_draw") < 3 then
          room:addPlayerMark(player, "@hx__zongheng_draw", 1)
          player:drawCards(1, self.name)
        end
      end
    end
  end,
}
local hx__zongheng_sha = fk.CreateTriggerSkill{
  name = "#hx__zongheng_sha",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:getMark("@@hx__zongheng_slash") > 0 and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@hx__zongheng_slash", 0)
    room:askForUseActiveSkill(player, "bianzhuang")
  end,
}
hxqunyou__genie:addSkill(hx__yuanheng)
hxqunyou__genie:addSkill(hx__zongheng)
hx__zongheng:addRelatedSkill(hx__zongheng_sha)

--[[
--或牌名仅一项
local hxqunyou__mozhugeliang = General:new(extension, "hxqunyou__mozhugeliang","shu",3,7)
Fk:loadTranslationTable{
  ["hxqunyou__mozhugeliang"] = "末诸葛亮",
  ["designer:hxqunyou__mozhugeliang"] = "爱我十六",
  ["hx__tiansuan"] = "天算",
  ["hx__tiansuan&"] = "天算",
  [":hx__tiansuan"] = "每个阶段结束时，你可以使用本回合弃牌堆中一张与你本阶段使用过的牌花色相同的牌。",
  ["hx__wuming"] = "吾命",
  [":hx__wuming"] = "锁定技，若你的体力值为奇数/偶数，你视为拥有看破/火计。（OL界）",
  ["hx__jincui"] = "尽瘁",
  [":hx__jincui"] = "锁定技，你受到伤害时/弃牌阶段结束时，你使用一张牌，否则失去一点体力上限，视为使用一张基本牌/非伤害类普通锦囊牌。",
  ["#hx__tiansuan-use"] = "你可以使用其中一张牌",
  ["@@hx__tiansuan-phase"] = "天算",
  ["#hx__jincui-use1"] = "请你使用一张牌，否则失去一点体力上限，视为使用一张基本牌",
  ["#hx__jincui-use2"] = "请你使用一张牌，否则失去一点体力上限，视为使用一张非伤害类普通锦囊牌",
  ["#hx__jincui-target"] = "请选择此牌目标",
}

local hx__tiansuan = fk.CreateTriggerSkill {
  name = "hx__tiansuan",
  anim_type = "support",
  events = { fk.EventPhaseEnd },
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseEnd and player:hasSkill(self) then
      local room = player.room
      local names = {}
      room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
        local use = e.data[1]
        if use.from == player.id and use.card.suit ~= Card.NoSuit then
          table.insertIfNeed(names, use.card.trueName)
        end
      end, Player.HistoryPhase)
      local cards = {}
      room.logic:getEventsOfScope(GameEvent.MoveCards, 999, function (e)
        for _, move in ipairs(e.data) do
          if move.toArea == Card.DiscardPile then
            for _, info in ipairs(move.moveInfo) do
              if table.contains(names, Fk:getCardById(info.cardId).trueName) and table.contains(room.discard_pile, info.cardId) then
                room:addCardMark(Fk:getCardById(info.cardId), "@@hx__tiansuan-phase")
                table.insertIfNeed(cards, info.cardId)
              end
            end
          end
        end
      end, Player.HistoryTurn)
      if #cards > 0 then
        self.cost_data = cards
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = self.cost_data
    if #cards > 0 then
      room:moveCardTo(cards, Player.Special, player, fk.ReasonPut, self.name, "hx__tiansuan&", true, player.id)
      local use = U.askForPlayCard(room, player, nil,".|.|.|hx__tiansuan&", self.name, "#hx__tiansuan-use", {expand_pile = "hx__tiansuan&",bypass_distances = true, bypass_times = true})
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "hx__tiansuan&", nil, true, player.id)
    end
  end,
}

local hx__wuming = fk.CreateTriggerSkill{
  name = "hx__wuming",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.hp % 2 == 1 then
      room:handleAddLoseSkills(player, "ol_ex__kanpo", nil, true, false)
    elseif player.hp % 2 == 0 then
      room:handleAddLoseSkills(player, "ol_ex__huoji", nil, true, false)
    end
  end,
  refresh_events = {fk.HpChanged},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if player.hp % 2 == 1 and not player:hasSkill("ol_ex__kanpo", true) then
      if player:hasSkill("ol_ex__huoji", true) then
        room:handleAddLoseSkills(player, "-ol_ex__huoji", nil, true, false)
      end
      room:handleAddLoseSkills(player, "ol_ex__kanpo", nil, true, false)
    end
    if player.hp % 2 == 0 and not player:hasSkill("ol_ex__huoji", true)  then
      if player:hasSkill("ol_ex__kanpo", true) then
        room:handleAddLoseSkills(player, "-ol_ex__kanpo", nil, true, false)
      end
      room:handleAddLoseSkills(player, "ol_ex__huoji", nil, true, false)
    end
  end,
}


local hx__jincui = fk.CreateTriggerSkill{
  name = "hx__jincui",
  anim_type = "defensive",
  events = {fk.DamageInflicted,fk.EventPhaseEnd},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      return target == player and player:hasSkill(self)
    elseif event == fk.EventPhaseEnd then
      return player:hasSkill(self) and target == player and player.phase == Player.Discard
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageInflicted then
      local use = U.askForPlayCard(room, player, nil, nil, self.name, "#hx__jincui-use1::"..player.id, { bypass_times = true }, true)
      if use then
        use.card.skillName = self.name
        room:useCard(use)
      else
        room:changeMaxHp(player, -1)
        U.askForUseVirtualCard(room, player, U.getAllCardNames("b"), nil,self.name, "#hx__jincui-target", false)
      end
      data.damage = data.damage
    elseif event == fk.EventPhaseEnd then
      local use = U.askForPlayCard(room, player, nil, nil, self.name, "#hx__jincui-use2::"..player.id, { bypass_times = true }, true)
      if use then
        use.card.skillName = self.name
        room:useCard(use)
      else
        room:changeMaxHp(player, -1)
        local names = {}
        for _, id in ipairs(Fk:getAllCardIds()) do
          local card = Fk:getCardById(id)
          if card:isCommonTrick() and not card.is_damage_card and not card.is_derived and
            player:canUse(card) and not player:prohibitUse(card) then
            table.insertIfNeed(names, card.name)
          end
        end
        if #names > 0 then
          U.askForUseVirtualCard(room, player, names, nil,self.name, "#hx__jincui-target", false)
        end
      end
    end
  end,
}

hxqunyou__mozhugeliang:addSkill(hx__tiansuan)
hxqunyou__mozhugeliang:addSkill(hx__wuming)
hxqunyou__mozhugeliang:addSkill(hx__jincui)
--]]

local hxqunyou__limulu = General:new(extension, "hxqunyou__limulu","god",4,4,General.Female)
Fk:loadTranslationTable{
  ["hxqunyou__limulu"] = "利姆露",
  ["#hxqunyou__limulu"] = "史莱姆魔王",
  ["designer:hxqunyou__limulu"] = "decade",
  ["hx__daxianzhe"] = "大贤者",
  [":hx__daxianzhe"] = "锁定技，每当场上其他角色发动技能达至5次后，你选择令下面一项效果数字+1："..
  "<br>①弱点看破：你使用伤害牌指定其他角色为目标后，弃置对方区域内至多0牌。"..
  "<br>②并列演算：当你使用或打出闪或无懈可击时，依次摸1张锦囊牌。"..
  "<br>③思维加速：当你使用一张锦囊牌后，依次摸1张基本牌。"..
  "<br>④解析鉴定：当其他角色使用装备牌或装备牌被弃置后，你依次摸1张装备牌。",
  ["hx__nitai"] = "拟态",
  ["#hx__nitai_switch"] = "拟态",
  [":hx__nitai"] = "游戏开始时或出牌阶段开始时，你可以更改此技能的阴阳状态。阳：你使用杀造成伤害时，可以弃置一张牌对目标施加一层黑炎；阴：你受到杀的伤害时，可以摸一张牌然后可以弃置一张红桃牌并回复一点体力。"..
  "<br><b><font color='black'>#黑炎</font></b>：有黑炎的角色回合开始时，失去黑炎层数的体力并移除一层黑炎。",
  ["hx__baoshi"] = "暴食",
  [":hx__baoshi"] = "结束阶段，你可以弃置所有手牌对攻击范围内所有角色施加暴食。当拥有暴食的角色进入濒死状态后，你获得其一项技能然后移除所有暴食"..
  "<br><font color='red'>#暴食</font>：有暴食的角色使用牌只能指定拥有暴食的其他角色或利姆露，受到或造成伤害后，获得一层黑炎。",
  ["#hx__daxianzhe_1"] = "弱点看破",
  ["#hx__daxianzhe_2"] = "并列演算",
  ["#hx__daxianzhe_3"] = "思维加速",
  ["#hx__daxianzhe_4"] = "解析鉴定",
  ["hx__daxianzhe_1"] = "弱点看破",
  [":hx__daxianzhe_1"] = "你使用伤害牌指定其他角色为目标后，弃置对方区域内0牌。",
  ["hx__daxianzhe_2"] = "并列演算",
  [":hx__daxianzhe_2"] = "当你使用或打出闪或无懈可击时，摸1张锦囊牌。",
  ["hx__daxianzhe_3"] = "思维加速",
  [":hx__daxianzhe_3"] = "当你使用一张锦囊牌后，摸1张基本牌。",
  ["hx__daxianzhe_4"] = "解析鉴定",
  [":hx__daxianzhe_4"] = "当有角色使用或弃置装备牌后，摸1张装备牌。",
  ["#hx__daxianzhe"] = "你可以令一项效果的数字+1",
  ["#hx__daxianzhe_1-ask"] = "请选择要弃置的牌",
  ["@hx__daxianzhe"] = "发动次数",
  ["@hx__daxianzhe_1"] = "弱点看破+",
  ["@hx__daxianzhe_2"] = "并列演算+",
  ["@hx__daxianzhe_3"] = "思维加速+",
  ["@hx__daxianzhe_4"] = "解析鉴定+",
  ["#nitai-discard"] = "你可以弃置一张牌对目标施加一层黑炎",
  ["#nitai-discard2"] = "你可以弃置一张红桃牌并回复一点体力",
}

local hx__daxianzhe = fk.CreateTriggerSkill{
  name = "hx__daxianzhe",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.AfterSkillEffect},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and target and target ~= player and
    target:hasSkill(data) and data.visible
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {"hx__daxianzhe_1","hx__daxianzhe_2", "hx__daxianzhe_3", "hx__daxianzhe_4"}
    room:addPlayerMark(player, "@hx__daxianzhe", 1)
    if player:getMark("@hx__daxianzhe") % 5 == 0 then
      local choice = room:askForChoice(player, choices, self.name, "#hx__daxianzhe")
      if choice == "hx__daxianzhe_1" then
        room:addPlayerMark(player, "@hx__daxianzhe_1", 1)
      elseif choice == "hx__daxianzhe_2" then
        room:addPlayerMark(player, "@hx__daxianzhe_2", 1)
      elseif choice == "hx__daxianzhe_3" then
        room:addPlayerMark(player, "@hx__daxianzhe_3", 1)
      elseif choice == "hx__daxianzhe_4" then
        room:addPlayerMark(player, "@hx__daxianzhe_4", 1)
      end
      room:setPlayerMark(player, "@hx__daxianzhe", 0)
    end
  end,
}

local hx__daxianzhe_1 = fk.CreateTriggerSkill{
  name = "#hx__daxianzhe_1",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
    data.card and data.card.is_damage_card and data.to ~= player.id and player:getMark("@hx__daxianzhe_1") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    if not to:isAllNude() then
      local cards = room:askForCardsChosen(player, to, 0, player:getMark("@hx__daxianzhe_1"),"hej",self.name,"#hx__daxianzhe_1-ask")
      if #cards > 0 then
        room:moveCardTo(cards, Card.DiscardPile, player, fk.ReasonDiscard, self.name)
      end
    end
  end,
}

local hx__daxianzhe_2 = fk.CreateTriggerSkill{
  name = "#hx__daxianzhe_2",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing, fk.CardResponding, fk.CardUseFinished, fk.CardRespondFinished},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and 
      (data.card.name == "jink" or data.card.name == "nullification") and
      (event == fk.CardUsing or event == fk.CardResponding)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for i = 1 , 1 + player:getMark("@hx__daxianzhe_2") do
      local cards = player.room:getCardsFromPileByRule(".|.|.|.|.|trick")
      if #cards > 0 then
          room:obtainCard(player, cards[1], false, fk.ReasonDraw,player.id,self.name)
      end
    end
  end,
}

local hx__daxianzhe_3 = fk.CreateTriggerSkill{
  name = "#hx__daxianzhe_3",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing},
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) and data.card.type == Card.TypeTrick then
      if target == player then
        return true
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    for i = 1 , 1 + player:getMark("@hx__daxianzhe_3") do
      local cards = player.room:getCardsFromPileByRule(".|.|.|.|.|basic")
      if #cards > 0 then
          room:obtainCard(player, cards[1], false, fk.ReasonDraw, player.id, self.name)
      end
    end
  end
}

local hx__daxianzhe_4 = fk.CreateTriggerSkill{
  name = "#hx__daxianzhe_4",
  anim_type = "drawcard",
  events = {fk.CardUseFinished,fk.AfterCardsMove},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.CardUseFinished then
        return data.card.type == Card.TypeEquip and target ~= player
      end
      if event == fk.AfterCardsMove then
        for _, move in ipairs(data) do
          if move.moveReason == fk.ReasonDiscard then
            for _, info in ipairs(move.moveInfo) do
              if Fk:getCardById(info.cardId).type == Card.TypeEquip then
                return true
              end
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for i = 1 , 1 + player:getMark("@hx__daxianzhe_4") do
      local cards = player.room:getCardsFromPileByRule(".|.|.|.|.|equip")
      if #cards > 0 then
        room:obtainCard(player, cards[1], false, fk.ReasonDraw, player.id, self.name)
      end
    end
  end,
}

hxqunyou__limulu:addSkill(hx__daxianzhe)
hx__daxianzhe:addRelatedSkill(hx__daxianzhe_1)
hx__daxianzhe:addRelatedSkill(hx__daxianzhe_2)
hx__daxianzhe:addRelatedSkill(hx__daxianzhe_3)
hx__daxianzhe:addRelatedSkill(hx__daxianzhe_4)

local function setTYMouSwitchSkillState(player, generalName, skillName, isYang)
  if isYang == nil then
    isYang = player:getSwitchSkillState(skillName, true) == fk.SwitchYang
  else
    local switch_state = isYang and fk.SwitchYin or fk.SwitchYang
    if player:getSwitchSkillState(skillName, true) == switch_state then
      player.room:setPlayerMark(player, MarkEnum.SwithSkillPreName .. skillName, switch_state)
      player:setSkillUseHistory(skillName, 0, Player.HistoryGame)
    end
  end

  if Fk.generals["tymou2__" .. generalName] == nil then return end

  local from_name = "tymou__" .. generalName
  local to_name = "tymou__" .. generalName
  if isYang then
    to_name = "tymou2__" .. generalName
  else
    from_name = "tymou2__" .. generalName
  end
  if player.general == from_name then
    player.general = to_name
    player.room:broadcastProperty(player, "general")
  end
  if player.deputyGeneral == from_name then
    player.deputyGeneral = to_name
    player.room:broadcastProperty(player, "deputyGeneral")
  end
end

Fk:loadTranslationTable{
  ["tymou_switch"] = "%arg · %arg2",
  ["#tymou_switch-transer"] = "请选择 %arg 的阴阳状态",
}

local hx__nitai_switch = fk.CreateTriggerSkill{
  name = "#hx__nitai_switch",
  anim_type = "switch",
  events = {fk.GameStart,fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill("hx__nitai") and (event == fk.GameStart or (event == fk.EventPhaseStart and player.phase == Player.Play))
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name,"","拟态：是否更改【拟态】的阴阳状态？")
  end,
  on_use = function(self, event, target, player, data)
    setTYMouSwitchSkillState(player, "hxqunyou__limulu", "hx__nitai",
    player.room:askForChoice(player, { "tymou_switch:::hx__nitai:yang", "tymou_switch:::hx__nitai:yin" },
    "hx__nitai", "#tymou_switch-transer:::hx__nitai") == "tymou_switch:::hx__nitai:yin")
  end,
}

local hx__nitai = fk.CreateTriggerSkill{
  name = "hx__nitai",
  anim_type = "switch",
  switch_skill_name = "hx__nitai",
  events = {fk.DamageCaused,fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.name) and target == player and data.card and data.card.trueName == "slash" then
      if player:getSwitchSkillState(self.name, false) == fk.SwitchYang then
        return not player:isNude() and event == fk.DamageCaused
      else
        return event == fk.DamageInflicted
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local side = player:getSwitchSkillState(self.name, false)
    if side == fk.SwitchYang then
      local card = room:askForDiscard(player, 1, 1, true, self.name, true, ".", "#nitai-discard")
      if #card > 0 then
        self.cost_data = data.to
        return true
      end
    else
      return true
    end
    return false
  end,
  on_use = function(self, event, target, player, data)
      local room = player.room
      if player:getSwitchSkillState(self.name, true) == fk.SwitchYin then
        player:drawCards(1,self.name)
        local card = player.room:askForDiscard(player, 1, 1, true, self.name, true, ".|.|heart", "#nitai-discard2:::" .. data.card:toLogString())
        if #card > 0 then
          room:recover({
            who = player,
            num = 1,
            recoverBy = player,
            skillName = self.name
          })
        end
      else
        room:addPlayerMark(self.cost_data, "@hx__nitai_heiyan", 1)
      end
  end,
}

local hx__nitai_heiyan = fk.CreateTriggerSkill {
  name = "hx__nitai_heiyan",
  anim_type="negative",
  global = true,
  priority = 2,
  frequency = Skill.Compulsory,
  events = { fk.TurnStart },
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@hx__nitai_heiyan") > 0 and target == player
  end,
  on_use = function(self, event, target, player, data)
    local num = player:getMark("@hx__nitai_heiyan")
    player.room:sendLog({ type = "#hx__nitai_heiyan_Log", from = player.id,arg=num})
    player.room:removePlayerMark(player, "@hx__nitai_heiyan",1)
    player.room:loseHp(player, num, self.name)
  end,
}
Fk:addSkill(hx__nitai_heiyan)
Fk:loadTranslationTable {
  ["hx__nitai_heiyan"] = "黑炎",
  ["@hx__nitai_heiyan"] = "<font color='black'>黑炎</font>",
  ["#hx__nitai_heiyan_Log"] = "%from因【黑炎】效果，失去了%arg点体力",
  ["#hx__baoshi-choose"] = "暴食：选择 %src 的一个技能获得",
  ["#hx__baoshi_log"] = "%from 获得了 %to 的【%arg】",
}


hxqunyou__limulu:addSkill(hx__nitai)
hx__nitai:addRelatedSkill(hx__nitai_switch)


local hx__baoshi = fk.CreateTriggerSkill{
  name = "hx__baoshi",
  anim_type = "offensive",
  events = {fk.EventPhaseStart,fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    if event==fk.EventPhaseStart then
      return target == player and player:hasSkill(self) and player.phase == Player.Finish and not player:isKongcheng()
    else
      return player:hasSkill(self) and target.hp <= 0 and target:getMark("@hx__baoshi") > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
    return player.room:askForSkillInvoke(player, self.name,"","是否弃置所有手牌对攻击范围内所有角色施加【暴食】？")
    else
      self.cost_data = target
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room=player.room
    if event == fk.EventPhaseStart then
      room:throwCard(player:getCardIds(Player.Hand), self.name, player, player)
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if player:inMyAttackRange(p) then
          room:doIndicate(player.id, {p.id})
          room:addPlayerMark(p, "@hx__baoshi",1)
        end
      end
    else
      local skills = {}
      for _, s in ipairs(self.cost_data.player_skills) do
        if not (s.attached_equip or s.name[#s.name] == "&" or string.sub(s.name, 1,1) == "#" or
          table.contains({Skill.Limited, Skill.Lord}, s.frequency)) then
          table.insertIfNeed(skills, s.name)
        end
      end
      if #skills > 0 then
        local chosen = room:askForChoice(player, skills, self.name, "#hx__baoshi-choose:" .. self.cost_data.id)
        if chosen then
          room:handleAddLoseSkills(player, chosen, nil)
          room:doIndicate(player.id, {self.cost_data.id})
          room:sendLog{
            type = "#hx__baoshi_log",
            from = player.id,
            to = {self.cost_data.id},
            arg = chosen,
          }
        end
      end
      for _, p in ipairs(room.alive_players) do
        room:setPlayerMark(p,"@hx__baoshi", 0)
      end
    end
  end,
}

local hx__baoshi_prohibit = fk.CreateProhibitSkill{
  name = "#hx__baoshi_prohibit",
  is_prohibited = function(self, from, to)
    if from == to or to.general == "hxqunyou__limulu" then
      return false
    end
    if to:getMark("@hx__baoshi") == 0 then
      return from:getMark("@hx__baoshi") > 0
    end
  end,
}
local hx__baoshi_effect = fk.CreateTriggerSkill {
  name = "hx__baoshi_effect",
  anim_type="negative",
  global = true,
  priority = 2,
  frequency = Skill.Compulsory,
  events = {fk.Damage, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@hx__baoshi") > 0 and target == player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@hx__nitai_heiyan", 1)
  end,
}

Fk:addSkill(hx__baoshi_effect)
Fk:loadTranslationTable {
  ["#hx__baoshi_prohibit"] = "暴食",
  ["hx__baoshi_effect"] = "暴食",
  ["@hx__baoshi"] = "<font color='red'>暴食</font>",
}

hxqunyou__limulu:addSkill(hx__baoshi)
hx__baoshi:addRelatedSkill(hx__baoshi_prohibit)

local hxqunyou__ronghuanggai = General:new(extension, "hxqunyou__ronghuanggai","wu",4)
hxqunyou__ronghuanggai:addSkill("kurou")
hxqunyou__ronghuanggai:addSkill("ol_ex__zhaxiang")

Fk:loadTranslationTable{
  ["hxqunyou__ronghuanggai"] = "融黄盖",
  ["#hxqunyou__ronghuanggai"] = "轻身为国",
  ["designer:hxqunyou__ronghuanggai"] = "你家白鸽大人",
  ["~hxqunyou__ronghuanggai"] = "盖，有负公瑾重托……",
}


local hxqunyou__nijvshou = General:new(extension, "hxqunyou__nijvshou","qun",3)

Fk:loadTranslationTable{
  ["hxqunyou__nijvshou"] = "逆沮授",
  ["#hxqunyou__nijvshou"] = "万事逆转",
  ["designer:hxqunyou__nijvshou"] = "你家白鸽大人",
  ["hx__jijin"] = "极进",
  [":hx__jijin"] = "当你于出牌阶段使用牌时，若此牌的点数或花色与你本阶段使用的上一张牌不相同，你可以摸一张牌。",
  ["hx__shinan"] = "矢南",
  [":hx__shinan"] = "锁定技，当其他角色每回合首次受到伤害后，其回复1点体力，然后当其本回合受到伤害后，其失去1点体力。",
  ["$hx__jijin1"] = "徐徐图之，曹军难挡。",
  ["$hx__jijin2"] = "缓进渐行，敌军定可不战而退。",
  ["$hx__shinan1"] = "北归无望，亦不会与那曹贼共图。",
  ["$hx__shinan2"] = "北渡难回，清云不降。",
  ["~hxqunyou__nijvshou"] = "志坚心定，岂可与汉贼同谋？",
}

local hx__jijin = fk.CreateTriggerSkill{
  name = "hx__jijin",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return data.from == player.id and player:hasSkill(self.name) and player.phase == Player.Play and
      (data.extra_data or {}).hx__jianying_triggerable
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,
  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player.phase == Player.Play
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if data.card:getSuitString() ~= player:getMark("hx__jianying_suit-phase") or
        (data.card.number ~= player:getMark("hx__jianying_number-phase") and data.card.number ~= 0) then
      data.extra_data = data.extra_data or {}
      data.extra_data.hx__jianying_triggerable = true
    end
    if data.card.suit == Card.NoSuit then
      room:setPlayerMark(player, "hx__jianying_suit-phase", 0)
    else
      room:setPlayerMark(player, "hx__jianying_suit-phase", data.card:getSuitString())
    end
    room:setPlayerMark(player, "hx__jianying_number-phase", data.card.number)

    room:setPlayerMark(player, "@hx__jianying_record-phase", {data.card:getSuitString(true), data.card:getNumberStr()})
  end,
}

local hx__shinan = fk.CreateTriggerSkill{
  name = "hx__shinan",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and target ~= player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.isVirtualDMG then return end
    local firstDamage = room.logic:getActualDamageEvents(1, function(e) return e.data[1].to == target end)[1]
    if firstDamage and firstDamage.data[1] == data then
      player:broadcastSkillInvoke(self.name, 1)
      room:notifySkillInvoked(player, self.name)
      if target:isWounded() then
        room:recover{
          who = target,
          num = 1,
          skillName = self.name
        }
      end
    else
      player:broadcastSkillInvoke(self.name, 2)
      room:notifySkillInvoked(player, self.name, "negative")
      room:loseHp(target, 1, self.name)
    end
  end,
}

hxqunyou__nijvshou:addSkill(hx__jijin)
hxqunyou__nijvshou:addSkill(hx__shinan)


local hxqunyou__fkyshr = General:new(extension, "hxqunyou__fkyshr","qun",3,4)

Fk:loadTranslationTable{
  ["hxqunyou__fkyshr"] = "疯狂原始人",
  ["#hxqunyou__fkyshr"] = "食物链顶端",
  ["designer:hxqunyou__fkyshr"] = "焉",
  ["hx__yeman"] = "野蛮",
  [":hx__yeman"] = "锁定技，若你手牌中的牌名数和手牌数相等，你摸X张牌（X为你的体力值-已损失体力值且至少为1）。",
  ["hx__kongbu"] = "恐怖",
  ["#hx__kongbu_skill"] = "恐怖",
  [":hx__kongbu"] = "出牌阶段限一次，你可以弃置两张牌并获得一张不计入次数限制的杀（回合结束后失效）。你使用此杀造成伤害后，令你的所有技能视为未发动过。",
  ["#hx__kongbu"] = "出牌阶段限一次，你可以弃置两张牌并获得一张不计入次数限制的杀",
  ["@@hx__kongbu-turn"] = "恐怖",
  ["$hx__yeman1"] = "身体里沉睡的野兽，觉醒了！",
  ["$hx__yeman2"] = "...让我忘记疯狂！",
  ["$hx__kongbu1"] = "要么毁灭你，要么毁灭自己！",
  ["$hx__kongbu2"] = "彻底疯狂！！",
  ["~hxqunyou__fkyshr"] = "啊———",
}

local hx__yeman = fk.CreateTriggerSkill{
  name = "hx__yeman",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or player.dead then return false end
    local cards = player.player_cards[Player.Hand]
    local names = {}
    for _, id in ipairs(cards) do
      table.insertIfNeed(names, Fk:getCardById(id).trueName)
    end
    if #names == #cards then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local x = 2 * player.hp - player.maxHp
    player:drawCards(math.max(1, x), self.name)
  end,
}

local hx__kongbu = fk.CreateActiveSkill{
  name = "hx__kongbu",
  anim_type = "drawcard",
  card_num = 2,
  target_num = 0,
  prompt = "#hx__kongbu",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function (self, to_select, selected)
    return #selected < 2 and not Self:prohibitDiscard(to_select)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, player, player)
    if player.dead then return end
    local card = room:getCardsFromPileByRule("slash", 1, "allPiles")
    if #card > 0 then
      room:moveCards({
        ids = card,
        to = player.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonJustMove,
        proposer = player.id,
        skillName = self.name,
      })
      room:setCardMark(Fk:getCardById(card[1]), "@@hx__kongbu-turn", 1)
    end
  end,
  refresh_events = {fk.PreCardUse},
  can_refresh = function (self, event, target, player, data)
    return target == player and data.card:getMark("@@hx__kongbu-turn") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    data.extraUse = true
  end,
}

local hx__kongbu_targetmod = fk.CreateTargetModSkill{
  name = "#hx__kongbu_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and card:getMark("@@hx__kongbu-turn") > 0
  end,
}

local hx__kongbu_skill = fk.CreateTriggerSkill{
  name = "#hx__kongbu_skill",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" and
      data.card:getMark("@@hx__kongbu-turn") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skills = table.simpleClone(Fk.generals[player.general]:getSkillNameList(true))
    if player.deputyGeneral ~= "" then
      table.insertTableIfNeed(skills, Fk.generals[player.deputyGeneral]:getSkillNameList(true))
    end
    skills = table.filter(skills, function(s) return player:hasSkill(s) end)
    if #skills > 0 then
      for _, s in ipairs(skills) do
        player:setSkillUseHistory(s, 0, Player.HistoryPhase)
        player:setSkillUseHistory(s, 0, Player.HistoryTurn)
        player:setSkillUseHistory(s, 0, Player.HistoryRound)
        player:setSkillUseHistory(s, 0, Player.HistoryGame)
        room:sendLog{
          type = "%from的 %arg 技能被重置了！",
          from = player.id,
          arg = s,
        }
      end
    end
  end,
}

hxqunyou__fkyshr:addSkill(hx__yeman)
hxqunyou__fkyshr:addSkill(hx__kongbu)
hx__kongbu:addRelatedSkill(hx__kongbu_targetmod)
hx__kongbu:addRelatedSkill(hx__kongbu_skill)



local hxqunyou__muzhugeliang = General:new(extension, "hxqunyou__muzhugeliang","shu",3)

Fk:loadTranslationTable{
  ["hxqunyou__muzhugeliang"] = "暮诸葛亮",
  ["#hxqunyou__muzhugeliang"] = "丞相暮年",
  ["designer:hxqunyou__muzhugeliang"] = "普拉娜",
  ["hx__guanxing_mu"] = "观星",
  [":hx__guanxing_mu"] = "每轮开始时，你可以观看牌堆顶7X张牌，然后将任意数量的牌置于牌堆顶，将其余的牌置于牌堆底。（X为轮次数，X最大为3）",
  ["hx__kongcheng_mu"] = "空城",
  [":hx__kongcheng_mu"] = "锁定技，回合结束时，你将所有手牌置于武将牌上称为观星牌；回合开始时，你弃置全部观星牌。若你拥有观星牌，则其他角色使用牌指定你为目标时须猜测观星牌的种类，正确数小于2你摸一张牌，正确数小于3此牌对你无效。",
  ["hx__kongcheng_mu_basic"] = "基本牌",
  ["hx__kongcheng_mu_trick"] = "锦囊牌",
  ["hx__kongcheng_mu_equip"] = "装备牌",
  ["$hx__guanxing_mu1"] = "观星定中原，毕其功于一役！",
  ["$hx__guanxing_mu2"] = "天有不测风云，谨慎为妙。",
  ["$hx__kongcheng_mu1"] = "我城中并无一兵一卒。",
  ["$hx__kongcheng_mu2"] = "一曲高山流水，还请诸位静听。",
  ["~hxqunyou__muzhugeliang"] = "悠悠苍天，何薄于我……",
}

local hx__guanxing_mu = fk.CreateTriggerSkill{
  name = "hx__guanxing_mu",
  anim_type = "control",
  events = {fk.RoundStart},
  can_trigger = function(self, event, target, player, data)
    return  player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = math.min(7 * room:getTag("RoundCount"),21)
    room:askForGuanxing(player, room:getNCards(x))
  end,
}

local hx__kongcheng_mu = fk.CreateTriggerSkill{
  name = "hx__kongcheng_mu",
  frequency = Skill.Compulsory,
  anim_type = "control",
  events = {fk.TurnEnd ,fk.TurnStart,fk.TargetConfirming},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      if event == fk.TurnStart then
        return #player:getPile("hx__kongcheng_mu") > 0
      elseif event == fk.TargetConfirming then
        return data.from ~= player.id
      elseif event == fk.TurnEnd then
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnEnd then
      local cards = room:getCardsByArea(Player.Hand,player,true)
      player:addToPile("hx__kongcheng_mu", cards, true, self.name)
    elseif event == fk.TurnStart then
      room:moveCardTo(player:getPile("hx__kongcheng_mu"), Card.DiscardPile, player, fk.ReasonJustMove, self.name, nil, true, player.id)
    elseif event == fk.TargetConfirming then
      local choices = {"hx__kongcheng_mu_basic","hx__kongcheng_mu_trick","hx__kongcheng_mu_equip"}
      local tos = room:getPlayerById(data.from)
      local yes = room:askForChoices(tos, choices, 0, 3, self.name, "请猜测观星牌的种类：", false)
      for _, value in ipairs(yes) do
        table.removeOne(choices, value)
      end
      local right = 0
      for _, id in ipairs(player:getPile("hx__kongcheng_mu")) do
        local str = "hx__kongcheng_mu_"..Fk:getCardById(id):getTypeString()
        if table.contains(yes, str) then
          right = right + 1
          table.removeOne(yes, str)
        else
          table.removeOne(choices, str)
        end
      end
      right = right + #choices
      room:doBroadcastNotify("ShowToast", "猜对了"..right.."项")
      if right < 2 then
        player:drawCards(1, self.name)
      end
      if right < 3 then
        AimGroup:cancelTarget(data, player.id)
      end
    end
  end,
}


hxqunyou__muzhugeliang:addSkill(hx__guanxing_mu)
hxqunyou__muzhugeliang:addSkill(hx__kongcheng_mu)


local hxqunyou__ruifeng = General:new(extension, "hxqunyou__ruifeng","wu",4)
Fk:loadTranslationTable{
  ["hxqunyou__ruifeng"] = "芮锋",
  ["designer:hxqunyou__ruifeng"] = "星奴",
  ["hx__zhijin"] = "止晋",
  [":hx__zhijin"] = "锁定技，若你有装备区内有牌，其他角色计算与你的距离+X；反之，其他角色使用牌指定你为目标时你摸两张牌（ X为你的装备数+2）。",
  ["hx__cuntui"] = "寸退",
  [":hx__cuntui"] = "当你造成/受到伤害后，你可以令你与受伤角色/伤害来源各失去1点体力且本回合不能使用或打出牌。",
  ["$hx__zhijin1"] = "止于城前，我愧对于此？",
  ["$hx__zhijin2"] = "若以善兵而降，必失众命。",
  ["$hx__zhijin3"] = "今鉴以表上君令，诸军拼命死守尔。",
  ["$hx__cuntui1"] = "双方多有交战，不如暂退其锋。",
  ["$hx__cuntui2"] = "各军刀刃之利，皆可断链尓。",
  ["~hxqunyou__ruifeng"] = "以情死守，以忠相抵，然人败，国亡。",
  ["@@hx__cuntui_mark-turn"] = "本回合禁出牌",
}

local hx__zhijin = fk.CreateTriggerSkill{
  name = "hx__zhijin",
  frequency = Skill.Compulsory,
  anim_type = "drawcard",
  events = {fk.TargetConfirming},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      return data.from ~= player.id and #player:getCardIds{Player.Equip} == 0
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(2, self.name)
  end,
}

local hx__zhijin_distance = fk.CreateDistanceSkill{
  name = "#hx__zhijin_distance",
  correct_func = function(self, from, to)
    if to:hasSkill(self) and #to:getCardIds{Player.Equip} > 0 then
      return 2 + #to:getCardIds{Player.Equip}
    end
  end,
}

local hx__cuntui = fk.CreateTriggerSkill{
  name = "hx__cuntui",
  anim_type = "offensive",
  events = {fk.Damage, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damage then
      local to = data.to
      room:loseHp(player, 1, self.name)
      room:addPlayerMark(player, "@@hx__cuntui_mark-turn", 1)
      room:loseHp(to, 1, self.name)
      room:addPlayerMark(to, "@@hx__cuntui_mark-turn", 1)
    else
      local from = data.from
      room:loseHp(player, 1, self.name)
      room:addPlayerMark(player, "@@hx__cuntui_mark-turn", 1)
      room:loseHp(from, 1, self.name)
      room:addPlayerMark(from, "@@hx__cuntui_mark-turn", 1)
    end
  end,
}

local hx__cuntui_prohibit = fk.CreateProhibitSkill{
  name = "#hx__cuntui_prohibit",
  prohibit_use = function(self, player, card)
      return player:getMark("@@hx__cuntui_mark-turn") > 0
  end,
  prohibit_response = function(self, player, card)
      return player:getMark("@@hx__cuntui_mark-turn") > 0
  end,
}


hxqunyou__ruifeng:addSkill(hx__zhijin)
hx__zhijin:addRelatedSkill(hx__zhijin_distance)
hxqunyou__ruifeng:addSkill(hx__cuntui)
hx__cuntui:addRelatedSkill(hx__cuntui_prohibit)



local hxqunyou__xingsunce = General:new(extension, "hxqunyou__xingsunce","wu",1,4)
hxqunyou__xingsunce.shield = 2
Fk:loadTranslationTable{
  ["hxqunyou__xingsunce"] = "醒孙策",
  ["#hxqunyou__xingsunce"] = "在路上了",
  ["designer:hxqunyou__xingsunce"] = "欧阳锋",
  ["$mou__jiang_hxqunyou__xingsunce1"] = "吾乃江东小霸王孙伯符！",
  ["$mou__jiang_hxqunyou__xingsunce2"] = "江东子弟，何惧于天下！",
  ["$mou__yingzi_hxqunyou__xingsunce1"] = "公瑾，助我决一死战！",
  ["$mou__yingzi_hxqunyou__xingsunce2"] = "尔等看好了！",
  ["$yinghun_hxqunyou__xingsunce1"] = "父亲，助我背水一战！",
  ["$yinghun_hxqunyou__xingsunce2"] = "孙氏英烈，庇佑江东！",
  ["$mou__zhiba_hxqunyou__xingsunce1"] = "是友是敌，一探便知。",
  ["$mou__zhiba_hxqunyou__xingsunce2"] = "我若怕你，非孙伯符也！",
  ["~hxqunyou__xingsunce"] = "内事不决问张昭，外事不决问周瑜……",
}


hxqunyou__xingsunce:addSkill("mou__jiang")
hxqunyou__xingsunce:addSkill("mou__yingzi")
hxqunyou__xingsunce:addSkill("yinghun")
hxqunyou__xingsunce:addSkill("mou__zhiba")



local hxqunyou__T800 = General:new(extension, "hxqunyou__T800","god",4)
Fk:loadTranslationTable{
  ["hxqunyou__T800"] = "T800",
  ["#hxqunyou__T800"] = "天网终结者",
  ["designer:hxqunyou__T800"] = "武安君",
  ["hx__jinshu"] = "金属",
  [":hx__jinshu"] = "锁定技，每回合开始时你将护甲值补至2。当你的护甲变为0时，你选择一名角色对其造成1火焰伤害。",
  ["hx__jianmie"] = "歼灭",
  ["#hx__jianmie_effect"] = "歼灭",
  [":hx__jianmie"] = "每轮限两次，"..
"<br/>1.一个回合开始时，你可以失去一点体力并摸两张牌，你以此法获得的牌不可被【闪】响应。"..
"<br/>2.失去1点护甲后，你可以令一名角色进行一次判定，若结果为：黑色，你对该角色造成1雷电伤害；红色，你弃置该角色至多两张手牌。",
  ["hx__shenpan"] = "审判",
  [":hx__shenpan"] = "锁定技，你使用【杀】造成伤害时，若目标角色体力值小于你，此【杀】伤害+1。",
  ["hx__zhongjie"] = "终结",
  ["#hx__zhongjie"] = "你可以弃置任意名角色的所有手牌然后对这些角色造成两点雷电伤害。",
  [":hx__zhongjie"] = "限定技，出牌阶段，你可以弃置任意名角色的所有手牌然后对这些角色造成两点雷电伤害。",
  ["$hx__jinshu1"] = "The final battle would not be fought in the future, it would be fought here in our present.",
  ["$hx__jinshu2"] = "l swear l won't kill anyone, but !'ll beat them badly.",
  ["$hx__jianmie1"] = "(突！)",
  ["$hx__jianmie2"] = "（突！突！突！突！）",
  ["$hx__shenpan"] = "（M249枪声）",
  ["$hx__zhongjie1"] = "（Terminated）",
  ["$hx__zhongjie2"] = "（Fighting Shadows）",
  ["~hxqunyou__T800"] = "（boom！！！）",
  ["@@hx__jianmie-turn"] = "不可被闪响应",
}

local hx__jinshu = fk.CreateTriggerSkill{
  name = "hx__jinshu",
  frequency = Skill.Compulsory,
  anim_type = "defensive",
  events = {fk.TurnStart,fk.HpChanged},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.TurnStart then
        return player.shield < 2
      else
        return player.shield == 0 and target == player
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      if player.shield == 0 then
        room:changeShield(player, 2)
      elseif player.shield == 1 then
        room:changeShield(player,1)
      end
    else
      local tos = room:askForChoosePlayers(player, table.map(room:getAllPlayers(), Util.IdMapper), 1, 1, "请选择一名角色对其造成1火焰伤害", self.name, false)
      local to = room:getPlayerById(tos[1])
      room:damage{
        from = player,
        to = to,
        damage = 1,
        damageType = fk.FireDamage,
        skillName = self.name,
      }
    end
  end,
}

local hx__jianmie = fk.CreateTriggerSkill{
  name = "hx__jianmie",
  anim_type = "offensive",
  events = {fk.TurnStart,fk.HpChanged},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryRound) < 2 then
      if event == fk.TurnStart then
        return true
      elseif event == fk.HpChanged then
        return data.reason == "damage" and data.shield_lost > 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      room:loseHp(player, 1, self.name)
      player:drawCards(2, self.name, nil,"@@hx__jianmie-turn")
    else
      local tos = room:askForChoosePlayers(player, table.map(room:getAllPlayers(), Util.IdMapper), 1, 1, "请选择一名角色令其判定，若结果为：黑色，你对该角色造成1雷电伤害；红色，你弃置该角色至多两张手牌。", self.name, false)
      local to = room:getPlayerById(tos[1])
      local judge = {
        who = to,
        reason = self.name,
        pattern = ".|.",
      }
      room:judge(judge)
      if judge.card.color == Card.Black then
        room:damage{
          from = player,
          to = to,
          damage = 1,
          damageType = fk.ThunderDamage,
          skillName = self.name,
        }
      elseif judge.card.color == Card.Red then
        if #to:getCardIds(Player.Hand) == 0 then return end
        local card = room:askForCardsChosen(player, to,1,2, "h", self.name)
        room:throwCard(card, self.name, to, player)
      end
    end
  end,
}

local hx__jianmie_effect = fk.CreateTriggerSkill{
  name = "#hx__jianmie_effect",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" and data.card:getMark("@@hx__jianmie-turn") > 0
  end,
  on_use = function(self, event, target, player, data)
    data.disresponsiveList = table.map(player.room.alive_players, Util.IdMapper)
  end,
}


local hx__shenpan = fk.CreateTriggerSkill{
  name = "hx__shenpan",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    local logic = player.room.logic
    if target == player and player:hasSkill(self) and player.hp > data.to.hp and data.card and data.card.trueName == "slash" then
      return data.by_user
    end
  end,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end,
}

local hx__zhongjie = fk.CreateActiveSkill{
  name = "hx__zhongjie",
  anim_type = "offensive",
  frequency = Skill.Limited,
  card_num = 0,
  min_target_num = 1,
  max_target_num = 999,
  prompt = "#hx__zhongjie",
  can_use = function(self, player)
    local targets = table.filter(Fk:currentRoom().alive_players, function(p) return p ~= player end)
    for _, tar in ipairs(targets) do
      return #tar:getHandlyIds() > 0 and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
    end
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    local target = Fk:currentRoom():getPlayerById(to_select)
    return to_select ~= Self.id and #target:getHandlyIds() > 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:sortPlayersByAction(effect.tos)
    for _, pid in ipairs(effect.tos) do
      local to = room:getPlayerById(pid)
      local cardIds = {}
      local handCards = to:getHandlyIds()
      for _, card in ipairs(handCards) do
        table.insert(cardIds, card)
      end
      if #cardIds > 0 then
        room:moveCards({
          from = to.id,
          ids = cardIds,
          toArea = Card.DiscardPile,
          moveReason = fk.ReasonDiscard,
          proposer = player.id,
          skillName = self.name,
        })
      end
    end
    for _, pid in ipairs(effect.tos) do
      local to = room:getPlayerById(pid)
      room:damage({
        from = player,
        to = to,
        damage = 2,
        damageType = fk.ThunderDamage,
        skillName = self.name,
      })
    end
  end,
}

hxqunyou__T800:addSkill(hx__jinshu)
hxqunyou__T800:addSkill(hx__jianmie)
hx__jianmie:addRelatedSkill(hx__jianmie_effect)
hxqunyou__T800:addSkill(hx__shenpan)
hxqunyou__T800:addSkill(hx__zhongjie)


local hxqunyou__yanchixia = General:new(extension, "hxqunyou__yanchixia","god",4,6)
Fk:loadTranslationTable{
  ["hxqunyou__yanchixia"] = "燕赤霞",
  ["designer:hxqunyou__yanchixia"] = "武安君",
  ["hx__jiefa"] = "借法",
  ["#hx__jiefa_get"] = "借法",
  ["#hx__jiefa_dis"] = "借法",
  ["#hx__jiefa_sha"] = "借法",
  [":hx__jiefa"] = "①游戏开始时或每轮开始时，若你的「卦象」标记数不大于1，则你将「卦象」标记补至3枚。②出牌阶段限一次，你可："..
"<br/>1.移去两枚「卦象」标记令你本回合使用【杀】无视距离且不可被响应；"..
"<br/>2.你可移去一枚「卦象」标记然后声明一种牌的类型并进行一次判定，若判定牌的类型与声明的类型："..
"<br/>相同，你摸两张牌并回复1点体力；"..
"<br/>不同，你对一名其他角色造成X点雷电伤害（X为该角色已损失体力值且至少为1）。",
  ["hx__chongsheng"] = "重生",
  [":hx__chongsheng"] = "每局限两次，当你进入濒死状态时，你可以将体力值回复至3点并弃置所有手牌，若如此做，你可以选择一名其他角色，你摸等同于其手牌数张牌并弃置其至多3张牌或获得其区域内至多2张牌。",
  ["hx__shenjian"] = "神剑",
  [":hx__shenjian"] = "锁定技，你对一名「天劫」层数小于3的其他角色造成伤害后，你令其获得一层「天劫」。拥有3层「天劫」的角色回合结束时，你对其造成2点雷电伤害并移去其所有「天劫」。",
  ["#hx__jiefa"] = "移去一枚或两枚「卦象」标记，执行相应效果",
  ["@hx__jiefa_guaxiang"] = "「卦象」",
  ["@hx__shenjian_tianjie"] = "「天劫」",
  ["@@hx__jiefa_sha-turn"] = "【杀】增益",
  ["$hx__jiefa"] = "天地无极，乾坤借法！    ",
  ["$hx__chongsheng"] = "金身不灭，元神出窍！金身不灭，元神出窍！    ",
  ["$hx__shenjian"] = "    轩辕神剑！",
  ["~hxqunyou__yanchixia"] = "人不像人，鬼不像鬼，人有人造反，鬼有鬼作怪，天下间没有一处是净土。",
}


local hx__jiefa = fk.CreateActiveSkill{
  name = "hx__jiefa",
  card_num = 0,
  target_num = 0,
  prompt = "#hx__jiefa",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and player:getMark("@hx__jiefa_guaxiang") > 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:removePlayerMark(player, "@hx__jiefa_guaxiang", 1)
    local choice2 = {"移去一枚「卦象」然后声明一种牌的类型并进行一次判定"}
    if player:getMark("@hx__jiefa_guaxiang") > 1 then
      table.insert(choice2, "移去两枚「卦象」标记令你本回合使用【杀】无视距离且不可被响应")
    end
    local choose = room:askForChoice(player, choice2, self.name)
    if choose == "移去一枚「卦象」然后声明一种牌的类型并进行一次判定" then
      local choice = room:askForChoice(player, {"basic", "trick", "equip"}, self.name)
      local ty
      if choice == "basic" then
        ty = Card.TypeBasic
      elseif choice == "trick" then
        ty = Card.TypeTrick
      else
        ty = Card.TypeEquip
      end
      room:sendLog{
        type = "%from “%arg2” 声明了类型 %arg",
        from = player.id,
        arg = choice,
        arg2 = self.name,
        toast = true,
      }
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".|.",
      }
      room:judge(judge)
      if judge.card.type == ty then
        player:drawCards(2, self.name)
        room:recover{
          who = player,
          num = 1,
          skillName = self.name,
          recoverBy = player,
        }
      else
        local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "请选择一名其他角色对其造成X点雷电伤害（X为该角色已损失体力值且至少为1", self.name, false)
        local to = room:getPlayerById(tos[1])
        local x = math.max(to.maxHp - to.hp, 1)
        room:damage{
          from = player,
          to = to,
          damage = x,
          damageType = fk.ThunderDamage,
          skillName = self.name,
        }
      end
    elseif choose == "移去两枚「卦象」标记令你本回合使用【杀】无视距离且不可被响应" then
      room:addPlayerMark(player, "@@hx__jiefa_sha-turn")
    end
  end,
}


local hx__jiefa_dis = fk.CreateTargetModSkill{
  name = "#hx__jiefa_dis",
  main_skill = hx__jiefa,
  frequency = Skill.Compulsory,
  bypass_distances =  function(self, player, skill, card, to)
    return player:hasSkill(hx__jiefa) and skill.trueName == "slash_skill" and player:getMark("@@hx__jiefa_sha-turn") > 0
  end,
}

local hx__jiefa_sha = fk.CreateTriggerSkill{
  name = "#hx__jiefa_sha",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@hx__jiefa_sha-turn") > 0 and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.disresponsiveList = table.map(room.alive_players, Util.IdMapper)
  end,
}


local hx__jiefa_get = fk.CreateTriggerSkill{
  name = "#hx__jiefa_get",
  anim_type = "support",
  events = {fk.RoundStart,fk.GameStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and player:getMark("@hx__jiefa_guaxiang") <= 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@hx__jiefa_guaxiang", 3)
  end,
}

local hx__chongsheng = fk.CreateTriggerSkill{
  name = "hx__chongsheng",
  anim_type = "support",
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) < 2
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:isWounded() and not player.dead then
      room:recover({
        who = player,
        num = 3-player.hp,
        recoverBy = player,
        skillName = self.name
      })
    end
    room:throwCard(player:getCardIds(Player.Hand), self.name, player, player)
    local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "选择一名其他角色，你摸等同于其手牌数张牌并弃置其至多3张牌或获得其区域内至多2张牌）", self.name, true)
    if #tos == 0 then return end
    local to = room:getPlayerById(tos[1])
    if #to:getCardIds(Player.Hand) == 0 then return end
    player:drawCards(#to:getCardIds(Player.Hand), self.name)
    local choice = room:askForChoice(player, {"弃置其至多3张牌", "获得其区域内至多2张牌"}, self.name)
    if choice == "弃置其至多3张牌" then
      local card = room:askForCardsChosen(player, to, 1, 3, "he", self.name)
      room:throwCard(card, self.name, to, player)
    elseif choice == "获得其区域内至多2张牌" then
      local card2 = room:askForCardsChosen(player, to, 1, 2, "hej", self.name)
      room:moveCards{
        ids = card2,
        from = to.id,
        to = player.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonJustMove,
        skillName = self.name,
        proposer = player.id,
      }
    end
  end,
}

local hx__shenjian = fk.CreateTriggerSkill{
  name = "hx__shenjian",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = { fk.Damage, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.Damage then
      return player:hasSkill(self) and player == target and data.to ~= player and not data.to.dead and data.to:getMark("@hx__shenjian_tianjie") < 3
    else
      return player:hasSkill(self) and target:getMark("@hx__shenjian_tianjie") == 3
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damage then
      room:addPlayerMark(data.to, "@hx__shenjian_tianjie")
    else
      room:damage{
        from = player,
        to = target,
        damage = 2,
        damageType = fk.ThunderDamage,
        skillName = self.name,
      }
      room:setPlayerMark(target, "@hx__shenjian_tianjie", 0)
    end
  end,
}

hxqunyou__yanchixia:addSkill(hx__jiefa)
hx__jiefa:addRelatedSkill(hx__jiefa_get)
hx__jiefa:addRelatedSkill(hx__jiefa_dis)
hx__jiefa:addRelatedSkill(hx__jiefa_sha)
hxqunyou__yanchixia:addSkill(hx__chongsheng)
hxqunyou__yanchixia:addSkill(hx__shenjian)



local jiumeng_kakaluote = General:new(extension,"jiumeng_kakaluote","god",3,6)
local jiumeng_kakaluote_juexing = General:new(extension,"jiumeng_kakaluote_juexing","god",3,6)
jiumeng_kakaluote_juexing.total_hidden = true

local jiumeng_shunyi = fk.CreateActiveSkill{
  name = "jiumeng_shunyi",
  anim_type = "special",
  prompt = "#jiumeng_shunyi_prompt",
  can_use = function (self, player, card, extra_data)
    return player:usedSkillTimes(self.name) == 0
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 0,
  target_filter = Util.FalseFunc,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".",
    }
    room:judge(judge)
    if judge.card.color == Card.Black then
      room:recover{
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name,
      }
      local toId = room:askForChoosePlayers(player,table.map(room.alive_players,Util.IdMapper),1,1,"#jiumeng_shunyi_black",self.name,false,false)
      local to = room:getPlayerById(toId[1])
      local num = math.max(2,to:getLostHp())
      room:damage{
        to = to,
        damage = num,
        from = player,
        damageType = fk.ThunderDamage,
        skillName = self.name,
      }
    elseif judge.card.color == Card.Red then
      local choices = {"jiumeng_shunyi_exchange","jiumeng_shunyi_trick","jiumeng_shunyi_draw"}
      local num = 1
      if player:usedSkillTimes("jiumeng_bianshen_active",Player.HistoryGame) == 1 then
        num = 2
      end
      local choice = room:askForChoices(player,choices,num,num,self.name,"#jiumeng_shunyi_choose:::"..num,false,false,choices)
      if table.contains(choice,"jiumeng_shunyi_exchange") then
        local toId = room:askForChoosePlayers(player,table.map(room:getOtherPlayers(player),Util.IdMapper),1,1,"#jiumeng_shunyi_exchangechoose",self.name,false,false)
        local to = room:getPlayerById(toId[1])
        U.swapCards(room,player,player,to,player:getCardIds(Player.Hand),to:getCardIds(Player.Hand),self.name,Player.Hand)
      end
      if table.contains(choice,"jiumeng_shunyi_trick") then
        room:addPlayerMark(player,"@jiumeng_shunyi_trick",1)
      end
      if table.contains(choice,"jiumeng_shunyi_draw") then
        player:drawCards(4,self.name)
      end
    end
  end
}
local jiumeng_shunyi_delay = fk.CreateTriggerSkill{
  name = "#jiumeng_shunyi_delay",
  refresh_events = {fk.TurnEnd},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill("jiumeng_shunyi") and player:getMark("@jiumeng_shunyi_trick") > 0 and target and target ~= player
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player,"@jiumeng_shunyi_trick",0)
  end,
}
local jiumeng_shunyi_pro = fk.CreateProhibitSkill{
  name = "#jiumeng_shunyi_pro",
  is_prohibited = function (self, from, to, card)
    return to:hasSkill("jiumeng_shunyi") and to:getMark("@jiumeng_shunyi_trick") > 0 and to:usedSkillTimes("jiumeng_shunyi") == 0 and card.type == Card.TypeTrick
  end,
}

jiumeng_shunyi:addRelatedSkill(jiumeng_shunyi_delay)
jiumeng_shunyi:addRelatedSkill(jiumeng_shunyi_pro)
jiumeng_kakaluote:addSkill(jiumeng_shunyi)

Fk:loadTranslationTable{
  ["jiumeng_shunyi"] = "瞬移",
  [":jiumeng_shunyi"] = "锁定技。出牌阶段限一次，你可以进行判定，若结果为黑色。你回复一体力并对一名角色造成x点雷电伤害。（x为目标已损失体力值且至少为2）<br>"..
                        "若为红色，你选择一项（修改后改为选择两项）：1：与一名其他角色交换手牌。2：你在下回合内不能成为锦囊牌的目标。3：摸四张牌。",
  ["#jiumeng_shunyi_prompt"] = "瞬移：你可以进行判定并执行后续效果。",
  ["#jiumeng_shunyi_black"] = "瞬移：请选择你要造成伤害的目标角色。",
  ["jiumeng_shunyi_exchange"] = "与一名其他角色交换手牌",
  ["jiumeng_shunyi_trick"] = "你在下回合内不能成为锦囊牌的目标",
  ["jiumeng_shunyi_draw"] = "摸四张牌",
  ["#jiumeng_shunyi_choose"] = "瞬移：请选择%arg项。",
  ["#jiumeng_shunyi_exchangechoose"] = "瞬移：请选择要与你交换手牌的角色。",
  ["@jiumeng_shunyi_trick"] = "瞬移 防锦囊",
  ["#jiumeng_shunyi_delay"] = "瞬移",
  ["#jiumeng_shunyi_pro"] = "瞬移",

  ["$jiumeng_shunyi1"] = "音效",
}

local jiumeng_longquan = fk.CreateViewAsSkill{
  name = "jiumeng_longquan",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  pattern = "slash",
  prompt  = "jiumeng_longquan_fireslash",
  card_filter = function (self, to_select, selected, player)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip
  end,
  view_as = function (self, cards, player)
    if #cards ~= 1 then return nil end
    local card = Fk:cloneCard("fire__slash")
    card.skillName = "jiumeng_longquan"
    card:addSubcard(cards[1])
    return card
  end,
  before_use = function (self, player, use)
    use.additionalDamage = (use.additionalDamage or 0) + 1
    use.disresponsiveList = table.map(player.room.alive_players, Util.IdMapper)
  end,
  after_use = function (self, player, use)
    if player:usedSkillTimes(self.name,Player.HistoryGame) == 1 then
      player:drawCards(3,self.name)
    end
  end,
  enabled_at_play = function (self, player)
    return player:usedSkillTimes(self.name) == 0
  end,
  enabled_at_response = Util.FalseFunc,
}
local jiumeng_longquan_trigger = fk.CreateTriggerSkill{
  name = "#jiumeng_longquan_trigger",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified,fk.CardUsing,fk.PreCardEffect,fk.DamageCaused,fk.TurnStart},
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill("jiumeng_longquan") then
      if event == fk.PreCardEffect then
         if target ~= player and data.responseToEvent and data.card.name == "jink" then
            local src = player.room:getPlayerById(data.responseToEvent.from)
            return src == player
         end
      elseif event == fk.TurnStart then
        return true
      else  
        if target == player and data.card and data.card.trueName == "slash"  then
          if event == fk.DamageCaused then
            local isTransformed = data.card:isVirtual() or (data.card.skillName and data.card.skillName ~= "")
            if isTransformed and #data.card.subcards > 0 then
              local canevoke = true
              for _, v in ipairs(data.card.subcards) do
                if Fk:getCardById(v).type ~= Card.TypeEquip then
                  canevoke = false
                end
              end
              return canevoke
            end
          else
            if event == fk.TargetSpecified then
              return true
            else
              return not table.contains(player:getTableMark("jiumeng_longquan_hasevoked"),data.card.name)
            end  
          end
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if event == fk.PreCardEffect then
      return not target:isKongcheng() and room:askForSkillInvoke(player,self.name,nil,"#jiumeng_longquan_discard_evoke::"..target.id)
    elseif event == fk.CardUsing then
      return room:askForSkillInvoke(player,self.name,nil,"#jiumeng_longquan_draw")
    elseif event == fk.TurnStart then
      player.room:addPlayerMark(player,MarkEnum.SlashResidue.."-turn",2)
      player.room:addPlayerMark(player,MarkEnum.SlashBypassDistances.."-turn",3)
    else  
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.PreCardEffect then
      local card = room:askForCardChosen(player,target,"h",self.name,"#jiumeng_longquan_discard::"..target.id)
      room:throwCard(card,self.name,target,player)
    elseif event == fk.CardUsing then
      room:addTableMarkIfNeed(player,"jiumeng_longquan_hasevoked",data.card.name)
      if data.card.name == "slash" then
        player:drawCards(2,self.name)
      else
        player:drawCards(3,self.name)  
      end
    elseif event == fk.TargetSpecified then
      room:getPlayerById(data.to):addQinggangTag(data)
    else
      room:loseHp(data.to,data.damage,self.name)
      return true
    end
  end,
}

jiumeng_longquan:addRelatedSkill(jiumeng_longquan_trigger)
jiumeng_kakaluote:addSkill(jiumeng_longquan)

Fk:loadTranslationTable{
  ["jiumeng_longquan"] = "龙拳",
  [":jiumeng_longquan"] = "锁定技。你使用【杀】无视防具且每回合你使用的前三张【杀】无限制。若你使用的【杀】被响应，你可弃置此【杀】的目标一张手牌。你使用装备牌转化的【杀】造成的伤害视为体力流失。出牌阶段限一次。你可以将一张装备牌当作火【杀】使用，此【杀】造成的伤害加一且不可被响应，若为你首次发动此效果，你摸三张牌。每局游戏每种牌名限一次，当你使用【杀】时，你可摸两张牌，若为属性杀，改为三张。",
  ["jiumeng_longquan_fireslash"] = "龙拳：你可将一张装备牌当作火【杀】使用。",
  ["#jiumeng_longquan_trigger"] = "龙拳",
  ["#jiumeng_longquan_discard_evoke"] = "龙拳：你可弃置%dest一张手牌。",
  ["#jiumeng_longquan_draw"] = "龙拳：你可以摸一些牌。",
  ["#jiumeng_longquan_discard"] = "龙拳：请弃置%dest一张手牌。",
}

local jiumeng_bianshen_active = fk.CreateActiveSkill{
  name = "jiumeng_bianshen_active",
  anim_type = "special",
  prompt = "#jiumeng_bianshen_evoke",
  can_use = function (self, player, card, extra_data)
    return player:usedSkillTimes(self.name,Player.HistoryGame) == 0
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 0,
  target_filter = Util.FalseFunc,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    if player.general == "jiumeng_kakaluote" then
      room:setPlayerProperty(player,"general","jiumeng_kakaluote_juexing")
    elseif player.deputyGeneral and player.deputyGeneral == "jiumeng_kakaluote" then
      room:setPlayerProperty(player,"deputyGeneral","jiumeng_kakaluote_juexing")
    end
    room:recover{
      who = player,
      num = 5 - player.hp,
      recoverBy = player,
      skillName = self.name,
    }
    room:changeShield(player,5)
    local mark = player:getMarkNames()
    if #mark > 0 then
      for _, v in ipairs(mark) do
        if v:startsWith("@") then
          room:setPlayerMark(player,v,0)
        end
      end
    end
    room:handleAddLoseSkills(player,"jiumeng_jiewangquan|jiumeng_qigong|jiumeng_yuanqi|jiumeng_zhanyi",nil,nil,true)
    local choices = {"jiumeng_bianshen_kongzhi","jiumeng_bianshen_shuchu","Cancel"}
    local choice = room:askForChoice(player,choices,self.name,"#jiumeng_bianshen_choose",true,choices)
    if choice == "jiumeng_bianshen_kongzhi" then
      local tos = room:askForChoosePlayers(player,table.map(room.alive_players,Util.IdMapper),1,8,"jiumeng_bianshen_kongzhi_choose",self.name,true,false)
      local getequips = {}
      for _, v in ipairs(tos) do
        local to = room:getPlayerById(v)
        local num = math.min(#to:getCardIds({Player.Hand,Player.Equip}),5)
        local discards = room:askForCardsChosen(player,to,num,num,"he",self.name,"#jiumeng_bianshen_kongzhi_discard::"..v)
        if #discards > 0 then
          room:throwCard(discards,self.name,to,player)
        end
        for _, c in ipairs(to:getCardIds(Player.Equip)) do
          table.insertIfNeed(getequips,c)
        end
      end
      if #getequips > 0 then
        room:obtainCard(player,getequips,true,fk.ReasonPrey,player.id,self.name)
        local finish = false
        while #getequips > 0 and finish == false do
          local use = room:askForUseRealCard(player,getequips,self.name,"#jiumeng_bianshen_kongzhi_use",nil,true,true)
          if use then
            room:useCard(use)
            table.removeOne(getequips,use.card.id)
          else
            finish = true
          end
        end
      end
    elseif choice == "jiumeng_bianshen_shuchu" then
      local tos = room:askForChoosePlayers(player,table.map(room.alive_players,Util.IdMapper),1,8,"jiumeng_bianshen_shuchu_choose",self.name,true,false)
      for _, v in ipairs(tos) do
        local to = room:getPlayerById(v)
        room:damage{
          to = to,
          damage = 3,
          from = player,
          skillName = self.name,
        }
      end
      player:drawCards(5,self.name)
    end
    player:gainAnExtraTurn(false,self.name)
  end,
}

local jiumeng_bianshen = fk.CreateTriggerSkill{
  name = "#jiumeng_bianshen",
  anim_type = "support",
  frequency = Skill.Limited,
  events = {fk.EnterDying},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and target and target == player and player:usedSkillTimes("jiumeng_bianshen_active",Player.HistoryGame) == 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    player:setSkillUseHistory("jiumeng_bianshen_active",1,Player.HistoryGame)
    room:askForUseActiveSkill(player,"jiumeng_bianshen_active","#jiumeng_bianshen_evoke",true,nil,nil)
  end,
}

jiumeng_kakaluote:addSkill(jiumeng_bianshen_active)
jiumeng_bianshen_active:addRelatedSkill(jiumeng_bianshen)

Fk:loadTranslationTable{
  ["jiumeng_bianshen_active"] = "变身",
  [":jiumeng_bianshen_active"] = "限定技。出牌阶段或当你进入濒死状态时，你可回复至5点体力，并获得5护甲，修改【瞬移】然后立即执行一个额外回合，移除自身所有标记，获得【界王拳】，【气功】，【元气】，【战意】并可选择一项：1.弃置任意名角色各五张牌，然后获得他们装备区内所有牌并可立即使用之。2.对任意名角色各造成三点伤害，然后你摸五张牌。",
  ["#jiumeng_bianshen"] = "变身",
  ["#jiumeng_bianshen_evoke"] = "变身：你可回复至5点体力，获得5护甲并执行后续效果。",
  ["jiumeng_bianshen_kongzhi"] = "控制",
  [":jiumeng_bianshen_kongzhi"] = "弃置任意名角色各五张牌，然后获得他们装备区内所有牌并可立即使用之。",
  ["jiumeng_bianshen_shuchu"] = "输出",
  [":jiumeng_bianshen_shuchu"] = "对任意名角色各造成三点伤害，然后你摸五张牌。",
  ["jiumeng_bianshen_kongzhi_choose"] = "变身：请选择你要弃置牌的角色。",
  ["#jiumeng_bianshen_kongzhi_discard"] = "变身：请弃置%dest的牌。",
  ["#jiumeng_bianshen_kongzhi_use"] = "变身：你可使用你获得的装备牌。",
  ["jiumeng_bianshen_shuchu_choose"] = "变身：请选择你要造成伤害的角色。",
}

local jiumeng_jiewangquan = fk.CreateActiveSkill{
  name = "jiumeng_jiewangquan",
  anim_type = "offensive",
  prompt = "#jiumeng_jiewangquan_evoke",
  can_use = function (self, player, card, extra_data)
    return player:getHandcardNum() > 0
  end,
  card_num = 1,
  card_filter = function (self, to_select, selected, player)
    return #selected == 0
  end,
  target_num = 1,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and to_select ~= player.id
  end,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:throwCard(effect.cards,self.name,player,player)
    room:damage{
      to = target,
      damage = 1,
      damageType = fk.FireDamage,
      skillName = self.name,
      from = player,
    }
    local toId = room:askForChoosePlayers(player,table.map(room.alive_players,Util.IdMapper),1,1,"jiumeng_jiewangquan_chain",self.name,true,false)
    if #toId > 0 then
      local to = room:getPlayerById(toId[1])
      to:setChainState(true)
    end
  end,
}


jiumeng_kakaluote:addRelatedSkill(jiumeng_jiewangquan)

Fk:loadTranslationTable{
  ["jiumeng_jiewangquan"] = "界王拳",
  [":jiumeng_jiewangquan"] = "锁定技。出牌阶段，你可弃置一张牌，对一名角色造成1点火焰伤害并可横置一名角色。",
  ["#jiumeng_jiewangquan_evoke"] = "界王拳：你可弃置一张牌，对一名角色造成1点火焰伤害并可横置一名角色。",
  ["jiumeng_jiewangquan_chain"] = "界王拳：请选择你要横置的角色。",
}

local jiumeng_shenqu = fk.CreateTriggerSkill{
  name = "jiumeng_shenqu",
  anim_type = "defensive",
  priority = 1.1,
  events = {fk.DamageInflicted,fk.TurnStart,fk.CardUsing},
  frequency = Skill.Compulsory,
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.TurnStart then
        return true
      elseif event == fk.CardUsing then
        return target and target == player
      else
        return target and target == player
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      room:addPlayerMark(player,"jiumeng_shenqu_draw",1)
      if player:getMark("jiumeng_shenqu_draw") == 2 then
        room:setPlayerMark(player,"jiumeng_shenqu_draw",0)
        return true
      end
    else
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.DamageInflicted then
      local num = player:getMark("jiumeng_shenqu_inflect")
      if data.damage >= num then
        data.damage = num
        room:setPlayerMark(player,"jiumeng_shenqu_inflect",0)
      else
        room:removePlayerMark(player,"jiumeng_shenqu_inflect",data.damage)
      end
    elseif event == fk.CardUsing then
      player:drawCards(1,self.name)
      room:recover{
        who = player,
        num = 1,
        skillName = self.name,
        recoverBy = player,
      }
    else
      if player.shield > 0 then
        room:setPlayerMark(player,"jiumeng_shenqu_inflect",5)
      else
        room:setPlayerMark(player,"jiumeng_shenqu_inflect",3) 
      end
      if player.shield < 2 then
        room:changeShield(player,2-player.shield)
      end
    end
  end,
}

jiumeng_kakaluote:addRelatedSkill(jiumeng_shenqu)

Fk:loadTranslationTable{
  ["jiumeng_shenqu"] = "神躯",
  [":jiumeng_shenqu"] = "锁定技。每回合开始时，若你有护甲，你本回合最多受到5点伤害，否则你最多受到3点伤害，然后若你的护甲值小于2，你将护甲值设为2。你每使用2张牌就摸一张牌并回复1点体力。",
}

local jiumeng_qigong = fk.CreateTriggerSkill{
  name = "jiumeng_qigong",
  anim_type = "offensive",
  events = {fk.CardUsing},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and target and target == player and player.phase == Player.Play and player:usedSkillTimes(self.name) == 0 and data.card and data.card.trueName == "slash"
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name,nil,"#jiumeng_qigong_evoke")
  end,
  on_use = function (self, event, target, player, data)
    data.additionalDamage = (data.additionalDamage or 0) * 3 + 2
    data.card.skillName = self.name
  end,
  refresh_events = {fk.CardUseFinished},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self) and target and target == player and data.card and data.card.skillName == self.name
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local isResponse = false
    local use_events = room.logic.event_recorder[GameEvent.UseCard] or Util.DummyTable
    local cards = data.cardsResponded
    if cards ~= nil then
      for i = #use_events, 1, -1 do
        local e = use_events[i]
        local use = e.data[1]
        if e.data[1] == data then break end
        --FIXME:还需要更加精准的判断
        if table.contains(cards, use.card) then
          isResponse = true
        end
      end
    end
    if isResponse then
      room:recover{
        who = player,
        num = 1,
        skillName =self.name,
        recoverBy = player,
      }
      room:addPlayerMark(player,"@jiumeng_qi",1)
    end
  end,
}

jiumeng_kakaluote:addRelatedSkill(jiumeng_qigong)

Fk:loadTranslationTable{
  ["jiumeng_qigong"] = "气功",
  [":jiumeng_qigong"] = "锁定技。出牌阶段限一次。当你使用【杀】时，你可令此杀造成的伤害乘三。若此【杀】被响应，你回复一点体力并获得一枚“气”标记。",
  ["#jiumeng_qigong_evoke"] = "气功：你可令此【杀】造成的伤害乘三并有机会获得“气”。",
  ["@jiumeng_qi"] = "气",
}

local jiumeng_yuanqi = fk.CreateActiveSkill{
  name = "jiumeng_yuanqi",
  anim_type = "offensive",
  can_use = function (self, player, card, extra_data)
    return player:getMark("@jiumeng_qi") >= 3
  end,
  interaction = function (self, player)
    local all_choices = {"jiumeng_yuanqi_3","jiumeng_yuanqi_5"}
    local choices = {"jiumeng_yuanqi_3"}
    if player:getMark("@jiumeng_qi") >= 5 then
      table.insert(choices,"jiumeng_yuanqi_5")  
    end
    return UI.ComboBox{choices = choices,all_choices  = all_choices ,detailed = true}
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  min_target_num = 0,
  max_target_num = 1,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
    if not self.interaction.data then return end
    if self.interaction.data == "jiumeng_yuanqi_3" then
      return #selected == 0
    else
      return false  
    end
  end,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    if self.interaction.data == "jiumeng_yuanqi_3" then
      local target = room:getPlayerById(effect.tos[1])
      if target then
        room:removePlayerMark(player,"@jiumeng_qi",3)
        local num = math.max(2,target:getHandcardNum())
        room:damage{
          to = target,
          damage = num,
          from = player,
          skillName = self.name,
        }
      end
    else
      room:removePlayerMark(player,"@jiumeng_qi",5)
      player:gainAnExtraTurn(true,self.name)
    end
  end,
}

jiumeng_kakaluote:addRelatedSkill(jiumeng_yuanqi)

Fk:loadTranslationTable{
  ["jiumeng_yuanqi"] = "元气",
  [":jiumeng_yuanqi"] = "出牌阶段，你可以选择一项：1.移去3枚“气”，对一名角色造成y点伤害。（y为其手牌数且至少为2）；2.移去5枚“气”，在本回合结束后获得一个额外的回合。",
  ["jiumeng_yuanqi_3"] = "消耗三枚“气”",
  [":jiumeng_yuanqi_3"] = "对一名角色造成y点伤害。（y为其手牌数且至少为2）",
  ["jiumeng_yuanqi_5"] = "消耗五枚“气”",
  [":jiumeng_yuanqi_5"] = "在本回合结束后获得一个额外的回合。",
}

local jiumeng_zhanyi = fk.CreateTriggerSkill{
  name = "jiumeng_zhanyi",
  anim_type = "support",
  frequency = Skill.Limited,
  events = {fk.EnterDying},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and target and target == player and player:usedSkillTimes(self.name,Player.HistoryGame) == 0 and player.hp < 1
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:handleAddLoseSkills(player,"jiumeng_shenqu")
    room:recover{
      who = player,
      num = 6,
      skillName = self.name,
      recoverBy = player,
    }
    room:changeShield(player,5)
  end,
}

jiumeng_kakaluote:addRelatedSkill(jiumeng_zhanyi)

Fk:loadTranslationTable{
  ["jiumeng_zhanyi"] = "战意",
  [":jiumeng_zhanyi"] = "限定技。当你进入濒死状态时，你回复6点体力并获得5点护甲，失去【神躯】。",
}

Fk:loadTranslationTable{
  ["jiumeng_kakaluote"] = "卡卡罗特",
  ["jiumeng_kakaluote_juexing"] = "卡卡罗特",
  ["#jiumeng_kakaluote"] = "超级赛亚人",
  ["designer:jiumeng_kakaluote"] = "武安君",
  ["cv:jiumeng_kakaluote"] = "网络",
  ["illustrator:jiumeng_kakaluote"] = "网络",
  ["~jiumeng_kakaluote"] = "",
}


local hxqunyou__xzc_gj = General:new(extension, "hxqunyou__xzc_gj","wei",4)
Fk:loadTranslationTable{
  ["hxqunyou__xzc_gj"] = "戏志才&郭嘉",
  ["#hxqunyou__xzc_gj"] = "传说的天才",
  ["designer:hxqunyou__xzc_gj"] = "你家白鸽大人",
  ["hx__tiandu_bro"] = "天妒",
  [":hx__tiandu_bro"] = "你的判定牌生效后，你可以获得之。",
  ["hx__yice"] = "遗策",
  [":hx__yice"] = "当你受到1点伤害后，你可以进行判定，若结果为：黑色，你视为发动一次「遗计」；红色，你视为发动一次「筹策」。",
  ["hx__ximing"] = "戏命",
  [":hx__ximing"] = "锁定技，游戏开始时，你选择一名其他角色，当其受到伤害后，你受到等量的伤害；当其回复体力后，你回复等量的体力；当其进入濒死状态时，你重置「荐嘉」。",
  ["hx__jianjia"] = "荐嘉",
  [":hx__jianjia"] = "限定技，一名角色求桃结束时，若其体力值仍小于1，则你可以减一点体力上限令其回复体力值至一点。",
  ["@hx__ximing"] = "戏命",
  ["#hx__ximing-choose"] = "戏命: 请选择要戏命的角色",
  ["#hx__yice-draw"] = "遗策：令一名角色摸1张牌（戏命的角色多摸一张）",
  ["#hx__yice-discard"] = "遗策：弃置一名角色区域里的1张牌",
  ["$hx__tiandu_bro1"] = "随遇而安，闲适自得。",
  ["$hx__tiandu_bro2"] = "心境恬适，尽其在我。",
}

local updataXianfu = function (room, player, target)
  local mark = player:getTableMark("hx__ximing")
  table.insertIfNeed(mark[2], target.id)
  room:setPlayerMark(player, "hx__ximing", mark)
  local names = table.map(mark[2], function(pid) return Fk:translate(room:getPlayerById(pid).general) end)
  room:setPlayerMark(player, "@hx__ximing", table.concat(names, ","))
end

local hx__tiandu_bro = fk.CreateTriggerSkill{
  name = "hx__tiandu_bro",
  anim_type = "drawcard",
  events = {fk.FinishJudge},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player.room:getCardArea(data.card) == Card.Processing and target == player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:obtainCard(player.id, data.card, true, fk.ReasonJustMove)
  end,
}

local hx__yice = fk.CreateTriggerSkill{
  name = "hx__yice",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for i = 1, data.damage do
      if self.cancel_cost or not player:hasSkill(self) then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, data) then
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|^nosuit",
    }
    room:judge(judge)
    if judge.card.color == Card.Red then
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".|.|^nosuit",
      }
      room:judge(judge)
      if judge.card.color == Card.Red then
        local targets = table.map(room.alive_players, Util.IdMapper)
        local tos = room:askForChoosePlayers(player, targets, 1, 1, "#hx__yice-draw", self.name, false)
        local to = room:getPlayerById(tos[1])
        local num = 1
        local mark = player:getTableMark("hx__ximing")
        if #mark > 0 and table.contains(mark[1], to.id) then
          num = 2
          updataXianfu (room, player, to)
        end
        to:drawCards(num, self.name)
      elseif judge.card.color == Card.Black then
        local targets = table.map(table.filter(room.alive_players, function(p) return not p:isAllNude() end), Util.IdMapper)
        if #targets == 0 then return end
        local tos = room:askForChoosePlayers(player, targets, 1, 1, "#hx__yice-discard", self.name, false)
        local to = room:getPlayerById(tos[1])
        local card = room:askForCardChosen(player, to, "hej", self.name)
        room:obtainCard(player,card,false, fk.ReasonPrey)
      end
    elseif judge.card.color == Card.Black then
      player:drawCards(2, self.name)
      if player.dead or player:isKongcheng() then return end
      room:askForYiji(player, player:getCardIds("h"), room:getOtherPlayers(player, false), self.name, 0, 2)
    end
  end,
}


local hx__ximing = fk.CreateTriggerSkill{
  name = "hx__ximing",
  priority = 0.1,
  events = {fk.GameStart},
  frequency = Skill.Compulsory,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, self.name)
    player:broadcastSkillInvoke(self.name, math.random(2))
    local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player,false), Util.IdMapper), 1, 1, "#hx__ximing-choose", self.name, false, true)
    local mark = player:getTableMark(self.name)
    if #mark == 0 then mark = {{},{}} end
    table.insertIfNeed(mark[1], tos[1])
    room:setPlayerMark(player, self.name, mark)
  end,
}
local hx__ximing_delay = fk.CreateTriggerSkill{
  name = "#hx__ximing_delay",
  events = {fk.Damaged, fk.HpRecover,fk.EnterDying},
  frequency = Skill.Compulsory,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    local mark = player:getTableMark("hx__ximing")
    if not player.dead and not target.dead and #mark > 0 and table.contains(mark[1], target.id) then
      return event == fk.Damaged or player:isWounded()
    end
    if event == fk.EnterDying and player:hasSkill("hx__ximing") and target.hp < 1 then
      return #mark > 0 and table.contains(mark[1], target.id)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EnterDying then
      room:notifySkillInvoked(player, "hx__ximing","defensive")
      player:setSkillUseHistory("hx__jianjia", 0, Player.HistoryGame)
    else
      updataXianfu (room, player, target)
      room:sendLog{ type = "#SkillDelayInvoked", from = player.id, arg = "hx__ximing", }
      if event == fk.Damaged then
        player:broadcastSkillInvoke("hx__ximing", math.random(2)+2)
        room:damage{
          to = player,
          damage = data.damage,
          skillName = "hx__ximing",
        }
      else
        player:broadcastSkillInvoke("hx__ximing", math.random(2)+4)
        if player:isWounded() then
          room:recover{
            who = player,
            num = data.num,
            recoverBy = player,
            skillName = "hx__ximing",
          }
        end
      end
    end
  end,
}

local hx__jianjia = fk.CreateTriggerSkill{
  name = "hx__jianjia",
  anim_type = "defensive",
  frequency = Skill.Limited,
  events = {fk.AskForPeachesDone},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and player:usedSkillTimes(self.name,Player.HistoryGame) == 0 and target.hp < 1
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1)
    room:recover{
      who = target,
      num = 1-target.hp,
      recoverBy = player,
      skillName = self.name,
    }
  end
}

hxqunyou__xzc_gj:addSkill(hx__tiandu_bro)
hxqunyou__xzc_gj:addSkill(hx__yice)
hxqunyou__xzc_gj:addSkill(hx__ximing)
hx__ximing:addRelatedSkill(hx__ximing_delay)
hxqunyou__xzc_gj:addSkill(hx__jianjia)

local hxqunyou__jianshenwuming = General:new(extension,"hxqunyou__jianshenwuming","god",4,8)
local hxqunyou__jianshenwuming_juexing = General:new(extension,"hxqunyou__jianshenwuming_juexing","god",4,8)
hxqunyou__jianshenwuming_juexing.total_hidden = true


local hx_jianshen__getjianqi = function (room, player, num)
  local maxnum
  if player:usedSkillTimes("hx__tuiying",Player.HistoryGame) == 0 then
    maxnum = 3 - player:getMark("@hx__jianqi")
  else
    maxnum = 5 - player:getMark("@hx__jianqi")
  end
   local getnum = math.min(maxnum,num)
   room:addPlayerMark(player,"@hx__jianqi",getnum)
end

local hx__tianjian = fk.CreateTriggerSkill{
  name = "hx__tianjian",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TurnStart,fk.Damage,fk.Damaged},
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) and target and target == player then
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      hx_jianshen__getjianqi(room,player,3)
      local use = U.askForUseVirtualCard(room,player,"slash",nil,self.name,"#hx__tianjian__slash",true,true,true,true,nil,true)
      if use then
        room:removePlayerMark(player,"@hx__qianqi",1)
        local targets = TargetGroup:getRealTargets(use.tos)
        for _, v in ipairs(targets) do
          room:addTableMark(player,fk.MarkArmorInvalidTo.."-phase",v)
        end
        room:useCard(use)
        room:setPlayerMark(player,fk.MarkArmorInvalidTo.."-phase",0)
      end
    else
      if data.skillName ~= "hx__wanjian" then
         hx_jianshen__getjianqi(room,player,data.damage)
      end
    end
  end,
}
local hx__tianjian__targetmod = fk.CreateTargetModSkill{
  name= "#hx__tianjian__targetmod",
  bypass_distances = function (self, player, skill, card, to)
    return player:hasSkill("hx__tianjian") and card.trueName == "slash"
  end,
  bypass_times = function (self, player, skill, scope, card, to)
    return player:hasSkill("hx__tianjian") and card.trueName == "slash"
  end,

}

hx__tianjian:addRelatedSkill(hx__tianjian__targetmod)
hxqunyou__jianshenwuming:addSkill(hx__tianjian)

Fk:loadTranslationTable{
  ["hx__tianjian"] = "天剑",
  [":hx__tianjian"] = "锁定技，回合开始时，你获得3枚「剑气」标记，然后你可移去1枚「剑气」视为使用一张无视防具的【杀】。你使用【杀】无距离限制且不计入次数；你每造成或受到1点伤害，就获得1枚「剑气」（你最多拥有3枚「剑气」）。",
  ["@hx__jianqi"] = "剑气",
  ["#hx__tianjian__slash"] = "剑气：你可移去一枚“剑气”并视为使用一张无视防具的【杀】。",
}

local hx__jianqi = fk.CreateActiveSkill{
  name = "hx__jianqi",
  anim_type = "support",
  can_use = function (self, player, card, extra_data)
    return player:getMark("@hx__jianqi") > 0
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 1,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 
  end,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:removePlayerMark(player,"@hx__jianqi",1)
    room:recover{
      who = player,
      num = 1,
      skillName = self.name,
      recoverBy = player,
    }
    room:setPlayerMark(target,"@hx__jianqi__recover-turn","hx__jianqi__canrecover")
  end,
}
local hx__jianqi__trigger = fk.CreateTriggerSkill{
  name = "#hx__jianqi__trigger",
  anim_type = "support",
  events = {fk.DamageCaused},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill("hx__jianqi") and target and target == player and data.to:getMark("@hx__jianqi__recover-turn") == "hx__jianqi__canrecover"
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:recover{
      who = player,
      num = data.damage,
      recoverBy = player,
      skillName = self.name,
    }
  end,
}

hx__jianqi:addRelatedSkill(hx__jianqi__trigger)
hxqunyou__jianshenwuming:addSkill(hx__jianqi)

Fk:loadTranslationTable{
  ["hx__jianqi"] = "剑气",
  [":hx__jianqi"] = "出牌阶段，你可移去1枚剑气并回复1体力，然后选择一名角色，本回合你对其造成伤害时，你回复等量体力。",
  ["@hx__jianqi__recover-turn"] = "剑气",
  ["hx__jianqi__canrecover"] = "攻击回血",
  ["#hx__jianqi__trigger"] = "剑气",
}

local hx__wuxing = fk.CreateTriggerSkill{
  name = "hx__wuxing",
  anim_type = "drawcard",
  events = {fk.DrawNCards},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and target and target == player and player:getMark("@hx__jianqi") > 0 and data.n > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = player:getMark("@hx__jianqi")
    player:drawCards(num,self.name,"top",{"@hx__wuxing_cards-inarea",Player.Hand})
    if player:usedSkillTimes("hx__tuiying",Player.HistoryGame) ~= 0 then
      data.n = 0
      return true
    end
  end,
  refresh_events = {fk.PreHpRecover},
  can_refresh = function (self, event, target, player, data)
    return
        target == player and
        player:hasSkill(self) and
        data.card and
        data.card.trueName == "peach" and
        data.recoverBy and
        data.recoverBy == player and
        player.hp <= 1
  end,
  on_refresh = function (self, event, target, player, data)
    data.num = data.num + 1
  end,
}
local hx__wuxing_maxcard = fk.CreateMaxCardsSkill{
  name = "#hx__wuxing_maxcard",
  exclude_from = function (self, player, card)
    return player:hasSkill("hx__wuxing") and card:getMark("@hx__wuxing_cards-inarea") ~= 0
  end,
}
local hx__wuxing_prohibit = fk.CreateProhibitSkill{
  name = "#hx__wuxing_prohibit",
  is_prohibited = function (self, from, to, card)
    return to:hasSkill("hx__wuxing") and to.hp <= 2 and card.sub_type == Card.SubtypeDelayedTrick
  end,
}

hx__wuxing:addRelatedSkill(hx__wuxing_maxcard)
hx__wuxing:addRelatedSkill(hx__wuxing_prohibit)
hxqunyou__jianshenwuming:addSkill(hx__wuxing)

Fk:loadTranslationTable{
  ["hx__wuxing"] = "无形",
  [":hx__wuxing"] = "摸牌阶段，你额外摸x张牌（修改后改为摸x张牌），这些牌不计入你的手牌上限。（x为你的「剑气」数）。若你的体力值不大于2，你不能成为延时锦囊牌的目标。若你的体力值不大于1，你使用【桃】额外回复一点体力。",
  ["@hx__wuxing_cards-inarea"] = "无形",
}

local hx__tuiying = fk.CreateTriggerSkill{
  name = "hx__tuiying",
  anim_type = "support",
  frequency = Skill.Limited,
  events = {fk.EnterDying},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and target and target == player and player:usedSkillTimes(self.name,Player.HistoryGame) == 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if player.general == "hxqunyou__jianshenwuming" then
      room:setPlayerProperty(player,"general","hxqunyou__jianshenwuming_juexing")
    end
    room:recover{
      who = player,
      num = 3,
      recoverBy = player,
      skillName = self.name,
    }
    hx_jianshen__getjianqi(room,player,4)
    room:setPlayerMark(player,"@hx__tuiying","hx__tuiying_wudi")
    room:handleAddLoseSkills(player,"hx__guizhong|hx__wanjian")
  end,
  refresh_events = {fk.DamageInflicted,fk.TurnStart},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self) and target and target == player and player:getMark("@hx__tuiying") == "hx__tuiying_wudi"
  end,
  on_refresh = function (self, event, target, player, data)
    if event == fk.DamageInflicted then
      data.damage = 0
      return true
    else
      player.room:setPlayerMark(player,"@hx__tuiying",0)
    end
    
  end
}

hxqunyou__jianshenwuming:addSkill(hx__tuiying)

Fk:loadTranslationTable{
  ["hx__tuiying"] = "退隐",
  [":hx__tuiying"] = "限定技。当你进入濒死状态时，你回复3点体力，直到你的下回合开始前，你不会再受到伤害，获得4枚「剑气」并将「剑气」上限改为5，然后你获得【归宗】，【万剑】，修改【无形】。",
  ["@hx__tuiying"] = "退隐",
  ["hx__tuiying_wudi"] = "免伤",

  ["$hx__tuiying1"] = "世人皆道平凡好，惟有功名忘不了。",
  ["$hx__tuiying2"] = "一生日夕苦追求，一死却埋泉下了。",
}

local hx__guizhong = fk.CreateActiveSkill{
  name = "hx__guizhong",
  anim_type = "offensive",
  prompt = "#hx__guizhong_prompt",
  frequency = Skill.Compulsory,
  can_use = function (self, player, card, extra_data)
    return player:getMark("@hx__jianqi") >= 2 and player:getMark("@hx__guizhong-turn") == 0 and player:usedSkillTimes(self.name) == 0
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 0,
  target_filter = Util.FalseFunc,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:removePlayerMark(player,"@hx__jianqi",2)
    room:loseHp(player,1,self.name)
    room:addPlayerMark(player,"@hx__guizhong-turn",1)
  end,
}
local hx__guizhong_trigger = fk.CreateTriggerSkill{
  name = "#hx__guizhong_trigger",
  anim_type = "support",
  frequency = Skill.Compulsory,
  events = {fk.TurnStart},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill("hx__guizhong")
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    hx_jianshen__getjianqi(room,player,1)
  end,
  refresh_events = {fk.CardUsing,fk.DamageCaused},
  can_refresh = function (self, event, target, player, data)
    if event == fk.CardUsing then
      return player:hasSkill("hx__guizhong") and target and target == player and player:getMark("@hx__guizhong-turn") > 0 and data.card and data.card.trueName == "slash"
    else
      return player:hasSkill("hx__guizhong") and target and target == player and data.card and data.card.skillName == "hx__guizhong"
    end
    
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      data.additionalEffect = (data.additionalEffect or 0) + 1
      data.card.skillName = "hx__guizhong"
      room:setPlayerMark(player,"@hx__guizhong-turn",0)
    else
      local num = math.max(data.to:getLostHp(),2)
      room:loseHp(data.to,num,"hx__guizhong")
      return true
    end
  end,
}

hx__guizhong:addRelatedSkill(hx__guizhong_trigger)
hxqunyou__jianshenwuming:addRelatedSkill(hx__guizhong)

Fk:loadTranslationTable{
  ["hx__guizhong"] = "归宗",
  [":hx__guizhong"] = "锁定技。每回合开始时，你获得1枚「剑气」。出牌阶段限一次，你可移去2枚「剑气」并失去1点体力，使你本回合使用的下一张【杀】额外结算一次并将造成y点体力流失伤害。（y为目标已损失体力值且至少为2。）",
  ["#hx__guizhong_prompt"] = "归宗：你可移去2枚「剑气」并失去1点体力，强化你本回合使用的下一张【杀】。",
  ["@hx__guizhong-turn"] = "归宗",
  ["#hx__guizhong_trigger"] = "归宗",
}

local hx__wanjian = fk.CreateActiveSkill{
  name = "hx__wanjian",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  prompt = "#hx__wanjian_prompt",
  can_use = function (self, player, card, extra_data)
    return player:getMark("@hx__jianqi") > 0 and player:usedSkillTimes(self.name) < 3
  end,
  interaction = function (self, player)
    local num = player:getMark("@hx__jianqi")
    return UI.Spin{from = 1 ,to = num }
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  min_target_num = 1,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
    return self.interaction.data > 0
  end,
  on_use = function (self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:removePlayerMark(player,"@hx__jianqi",self.interaction.data)
    local choices = {"hx__wanjian_fire","hx__wanjian_thunder"}
    local damagetype = fk.FireDamage
    local choice = room:askForChoice(player,choices,self.name)
    if choice == "hx__wanjian_fire" then
      damagetype = fk.FireDamage
    else
      damagetype = fk.ThunderDamage
    end
    for _, v in ipairs(effect.tos) do
      local to = room:getPlayerById(v)
      if to.shield > 0 then
        room:changeShield(to,-to.shield)
      end
      room:damage{
        to = to,
        damage = self.interaction.data,
        damageType = damagetype,
        from = player,
        skillName = self.name,
      }
    end
    room:loseHp(player,2,self.name)
  end,
}

hxqunyou__jianshenwuming:addRelatedSkill(hx__wanjian)

Fk:loadTranslationTable{
  ["hx__wanjian"] = "万剑",
  [":hx__wanjian"] = "锁定技。出牌阶段限三次，你可消耗任意枚「剑气」，对任意名目标造成「剑气」数量点火焰或雷电伤害（此伤害不会获得「剑气」），然后你损失2点体力，若你移去了超过四枚「剑气」，你先移去所有目标的护甲再造成伤害。",
  ["#hx__wanjian_prompt"] = "万剑：你可消耗任意枚「剑气」，对任意名目标造成本次移去的「剑气」数量点火焰或雷电伤害。",
  ["hx__wanjian_fire"] = "火焰伤害",
  ["hx__wanjian_thunder"] = "雷电伤害",
}


Fk:loadTranslationTable{
  ["hxqunyou__jianshenwuming"] = "剑神无名",
  ["hxqunyou__jianshenwuming_juexing"] = "剑神无名",
  ["#hxqunyou__jianshenwuming"] = "武林至尊",
  ["designer:hxqunyou__jianshenwuming"] = "武安君",
  ["cv:hxqunyou__jianshenwuming"] = "网络",
  ["illustrator:hxqunyou__jianshenwuming"] = "网络",
  ["~hxqunyou__jianshenwuming"] = "",
}


return extension